By Kevin Hou
2 minute read
As of React 16.3, componentWillReceiveProps has been deprecated and was subsequently removed in React 17. Modern React applications should utilize getDerivedStateFromProps or functional components with the useEffect hook instead.
I discovered a pretty useful lifecycle event in React. I've typically only stuck to getInitialState, componentWillMount, and Render, but I just discovered componentWillReceiveProps.
This essentially gets called every time the component will receive a new or updated prop. This is really useful when you want to set a state equal to prop more than once in its lifecycle. The syntax is:
1componentWillReceiveProps(props) {
2 ...
3}
4
Try this out when you can! It's really useful.