You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a follow up for a change happened in v6. #1126
I do understand the reasons behind it, but it has introduced some inconsistent behavior between react-redux and react.
What is the current behavior?
Changes/initialization in component state in the constructor are available in the first render pass. It is guaranteed that the component is rendered only once with the correct local state.
Changes in redux store state in the component constructor are not available in the first render pass. The component is rendered using old store state in the first pass and causes a second render pass. The store state also may contain data from previous mounts, but since it is currently not possible to reset the store state from the constructor, old data is rendered in the first render pass.
class Comp extends Component {
constructor(props){
super(props);
const time = new Date();
// init local state
this.state={
time
isLoading: true
}
// init store state
props.dispatch({
type:'INIT_OR_RESET',
payload:{
time,
isLoading: true
}
})
}
render (){
const {myStoreState} = this.props;
if(myStoreState.time != this.state.time){
console.error("inconsistency");
}
....
}
}
What is the expected behavior?
Store state changes made in constructor should be available in the first render pass. Otherwise there should be an option for reset/init store state before the first render pass.
The text was updated successfully, but these errors were encountered:
Unfortunately, this isn't possible. There is no intermediate step between constructor and render that we can use to update the props provided to the connected component. The connect wrapper component has already been constructed and obtained the selected state from the store. If you check props in the constructor, you'll see it has old state data as well. React doesn't provide a way for us to intervene and update those props before rendering.
This is a follow up for a change happened in v6. #1126
I do understand the reasons behind it, but it has introduced some inconsistent behavior between react-redux and react.
What is the current behavior?
Changes/initialization in component state in the constructor are available in the first render pass. It is guaranteed that the component is rendered only once with the correct local state.
Changes in redux store state in the component constructor are not available in the first render pass. The component is rendered using old store state in the first pass and causes a second render pass. The store state also may contain data from previous mounts, but since it is currently not possible to reset the store state from the constructor, old data is rendered in the first render pass.
What is the expected behavior?
Store state changes made in constructor should be available in the first render pass. Otherwise there should be an option for reset/init store state before the first render pass.
The text was updated successfully, but these errors were encountered: