-
Notifications
You must be signed in to change notification settings - Fork 31
Fix react warning about causing a render during a render #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This commit does a few things: - Changes hooks to use useLayoutEffect instead of injecting during the render. This fixes the warning but comes with its own tradeoffs. For example, if an action is dispatched inside a useLayoutEffect inside a child component, it will be dispatched before the reducers/sagas have been injected. - Changes hooks to return booleans indicating whether or not the injection has completed. These can be used to mitigate the tradeoffs explained above. Components can check if the reducer/saga has been injected before rendering their chilldren. - Adds a warning to the README recommending `shouldHotReload` be set to false inside the redux-devtools options. This is because otherwise redux-devtools will re-dispatch previous actions when a reducer is injected. - Updates the docs in a few other spots explaining these changes - Bumps the major version, as this could break apps that dispatch actions inside useLayoutEffect
Question:
I'm not sure how late useLayoutEffect is deferring the domain injection? |
Actually I think the domain might be undefined the first time, I'll write a test to check |
If not I think this lib is headed towards a choice between HOC, or DIY wrapper using hooks api, or as you said, a factory to create your wrapper too. But a pure hooks approach just seems dead in the water unless one is willing to accept all the caveats. |
I agree with @danielrob. In my team we didn't want to deal with the caveats (and we felt like using I'm still happy to review this PR if you'd like to merge and release it but it does have an additional caveat that needs to be handled: The |
Niceeee |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍 I don't have the ability to test locally right now, but this looks good.
@julienben Do you want to review this before I merge it? I've removed the |
@julienben I merged but feel free to still review if you find some time |
This PR does a few things:
shouldHotReload
be set to false inside the redux-devtools options. This is because otherwise redux-devtools will re-dispatch previous actions when a reducer is injected.example
directoryNew Feature
createManager
factory. Usage:The books manager will only render its children after the reducer and saga have been injected.
See this comment for more details
Closes #19