3 ms·
>> When you see that the props have changed, what do you do? "What do I do in componentWillReceiveProps?" It's a good question. Looking through the code I se
by hoodoof 9y ago
>> When you see that the props have changed, what do you do?
"What do I do in componentWillReceiveProps?" It's a good question. Looking through the code I see alot of cases in which I am mapping new props to state, sometimes transforming received network data that is stored in redux, sometimes making a barrier to redirect to a different page if for example some condition has changed.
Perhaps these things are relics from before I really came to understand Redux - maybe in most cases I can just directly use props rather than having an intermediate setting of state.
- 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...