-
-
Notifications
You must be signed in to change notification settings - Fork 15.3k
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
Not working component update on state change. #57
Comments
I agree it's not very clear from the README, but Redux makes a hard assumption that you never mutate the state. Mutating the states defeats the purpose of Redux, and it's easy to avoid mutating it, so it's in fact a net good that the mutating code breaks early. We should make it explicit in the docs. Here's how your Store could look instead: const initialState = {
isAuthenticated: false,
email: ''
}
let setAuthenticated = (state) => {
return {
isAuthenticated: false,
...state
}
}
export default createStore(initialState, {
[LOGIN_SUCCESS]: (state, action) => {
return {
isAuthenticated: true,
email: action.email,
...state
}
},
[LOGIN_FAILURE]: (state, action) => {
return setAuthenticated(state)
},
[LOGOUT]: (state, action) => {
return setAuthenticated(state)
}
}) Does this solve your problem? |
(Suggestion: maybe deep freeze the state atom in development mode?) |
I added this to FAQ: https://github.com/gaearon/redux/blob/master/README.md#my-views-arent-updating Let me know if I missed something! |
I think I've heard that Facebook will freeze props and maybe state when |
Another option is to clone the state in dev before injecting it to the component. |
Much better! Thank you very much! :-) |
Few things:
First one: Why this? https://github.com/gaearon/redux/blob/master/src/components/Connector.js#L19 - not sure whether "flux" lib should cream about this part.
Second one: due to custom method shouldComponentUpdate "rerendering" of component does not work.
Look at my code:
Inside container component:
select method:
Store:
Then state.isAuthenticated will change to false. But Connector component does not render component "UserFooter" inside.
UserFooter component:
Last thing: Amazing work mate!
The text was updated successfully, but these errors were encountered: