-
Notifications
You must be signed in to change notification settings - Fork 48.5k
warn against dispatching redux actions during componentWillUpdate at runtime or in docs? #9693
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
Comments
The lifecycle is well documented from the perspective of one component, but what happens when a lifecycle method triggers and ancestor update is a big question in my mind. I've seen it work in most cases only to blow up in a few situations, and I don't really know why. |
I am not really sure we agree on what the issue is. I would argue that state changes in the lifecycle methods is always bad. I would also think that any state changes would run through the redux store, so the change has already happened before the lifecycle methods are invoked, or caused them to invoke. Ultimately it seems to me, granted with little information, that you should have an additional reducer listening for the action you dispatched that triggered the lifecycle methods in the first place, rather than rely on React to tell you when you made an error in Redux. (At least that seems like what you are asking, or suggesting, in the original issue.) |
@igreulich i agree with you, if you making something on |
@igreulich I know it seems like my question is Redux-specific but there are any number of ways you can trigger ancestor updates from
|
I understand that sounds ideal, for instance have a reducer or middleware that responds to the location change from |
@jedwards1211 it's hard to believe but did you try to use internal component state with |
Guys, everything I'm saying about redux, redux-form, react-router, etc. Is just an example. Here's what I'm trying to say: |
@jedwards1211 ok, i get it, but in
If you are
I think transactions in react and later on new reconciler So i think deal with it 🚀 |
I agree we should better document that you're not expected to cause side effects that synchronously update state in |
@gaearon here is my PR for the docs about this: https://github.com/facebook/react/pull/9694/files |
Hmm! @gaearon: Isn't it okay to call |
Thank you for filing this issue and raising these concerns. The documentation and source code for reactjs.org now lives in a different repository: reactjs/reactjs.org. (For more info on why we made this move, see issue #11075.) I closed the associated PR and added a comment explaining this. I've also moved your issue to the new repo: reactjs/react.dev#74 Let's continue the discussion there! Sorry for the inconvenience. |
Do you want to request a feature or report a bug?
Feature
What is the current behavior?
I had a component that was dispatching a redux action in its
componentWillUpdate
, which causing things to blow up in confusing ways. For instance, it was causing a different component'scomponentWillReceiveProps
to get called for the second time before itscomponentDidUpdate
got called, which led to various NPEs during the reconciliation process.What is the expected behavior?
It would be nice if anything that would trigger an update to during a call to a component's
componentWillUpdate
would immediately error out in dev mode, even if it's causing a different component to update (in my case, triggering an ancestorreact-redux
container to update). Would that be possible?Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
I'm seeing it with React 0.14.9 and Chrome on macOS. I can't say for sure if my code caused the same bugs with previous versions of React, but the blame rests on my code anyway.
The text was updated successfully, but these errors were encountered: