I have the following behavior:
@connect((state) => {
const props = {
isLoading: getIsLoadingSelector(state),
datafeched: getDataFeched(state),
};
// {isLoading: true, data: null} the first update. {isLoading: false, data: {...} } the second update
console.log(props);
return props;
})
class MyComponent extends PureComponent {
componentWillReceveProps(newProps) {
console.log(newProps); // It's only trigger for the first update `{isLoading: true, data: null}`
}
render() {
// ...
}
}
Could it be a bug or am I missing something?
99% of the time, "my component isn't re-rendering" is due to accidental mutation of your state. See http://redux.js.org/docs/faq/ReactRedux.html#react-not-rerendering .
@markerikson I don't think it's the case. mapStateToProps is called but the component is not re-rendered.
Yes, and if the individual fields in the object returned from mapState are the same references as they were before, then connect will think nothing has changed and not re-render. Please check your reducer logic.
Now, that said, looking at the example you've given, I would expect that datafeched changed from null to an object would trigger a re-render, so there may be something else going on. But, I can still safely say that this is highly unlikely to be a bug in connect.
Most helpful comment
99% of the time, "my component isn't re-rendering" is due to accidental mutation of your state. See http://redux.js.org/docs/faq/ReactRedux.html#react-not-rerendering .