3 ms·
>sometimes making a barrier to redirect to a different page if for example some condition has changed. That's a side effect. Move that to `componentDidUpdate`:
by danabramov 9y ago
>sometimes making a barrier to redirect to a different page if for example some condition has changed.
That's a side effect. Move that to `componentDidUpdate`: https://reactjs.org/blog/2018/03/27/update-on-async-rendering.html#side-effects-on-props-change https://reactjs.org/blog/2018/03/27/update-on-async-renderin...
>mapping new props to state
As I noted in https://news.ycombinator.com/item?id=16711813 https://news.ycombinator.com/item?id=16711813, usually it's not necessary (and complicated your code for nor benefit). For rare cases when it's useful, migrate to `getDerivedStateFromProps`: https://reactjs.org/blog/2018/03/27/update-on-async-rendering.html#updating-state-based-on-props https://reactjs.org/blog/2018/03/27/update-on-async-renderin...