Local state change triggering Redux's props change
See original GitHub issueWhat is the current behavior? Below code normally must change active component state just. But when use “return” in setState, changing props.dailyTasks of parent component.
_checkAll() {
const {checkAll} = this.state
this.setState(prevState => ({
checkAll: !checkAll,
dailyTasks: prevState.dailyTasks.map(
(el) => {
el.checked = !checkAll
return el
}
)
}))
}
What is the expected behavior? Below code works normally. Only the local state is changing.
_checkAll() {
const {checkAll} = this.state
this.setState(prevState => ({
checkAll: !checkAll,
dailyTasks: prevState.dailyTasks.map(
el => true ? { ...el, checked: !checkAll } : el
)
}))
}
Which versions of React, ReactDOM/React Native, Redux, and React Redux are you using? Which browser and OS are affected by this issue? Did this work in previous versions of React Redux?
"react": "16.8.3",
"react-dom": "16.8.3",
"react-native": "https://github.com/expo/react-native/archive/sdk-35.0.0.tar.gz",
"react-redux": "^7.1.1",
"redux": "^4.0.4",
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
React-redux : listening to state changes to trigger action
You want this state change C to trigger an asynchronous action X regardless of the action that originally caused the state change C....
Read more >How useSelector can trigger an update only when we want it to
Redux has an ever-changing store, but the way we access the state of the store is through its getState method. The reference to...
Read more >Actions and reducers: updating state - Human Redux
In Redux all changes to the application state happen via an "action. ... In Redux we say that actions (reports) are "dispatched" to...
Read more >How To Manage State in React with Redux - DigitalOcean
You can use a mix of local state and context to manage state. ... data into your components and dispatch new changes to...
Read more >Component state: local state, Redux store, and loaders
In a component built with ES6 classes, whenever the state changes (only available through setState function), React triggers a re-render ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@aytaceminoglu Your description of what the “bug” is isn’t exactly clear. But yes, you’re mutating state there. See https://redux.js.org/recipes/structuring-reducers/immutable-update-patterns and https://daveceddia.com/react-redux-immutability-guide/ for details.
Hi @markerikson thanks for info, i will be careful. You think that’s what caused the bug?