// Class
componentWillReceiveProps(nextProps) {
if (nextProps.data !== this.props.data) {
console.log('Prop Received: ', nextProps.data);
}
}
// React Hooks: componentWillReceiveProps
useEffect(() => {
console.log('Prop Received: ', props.data);
}, [props.data])
Created
November 7, 2019 20:29
-
-
Save WrathChaos/c476aac7c102ea2f01fd955c05b685f8 to your computer and use it in GitHub Desktop.
React Hooks: componentWillReceiveProps
@anandgupta193
Actually you need to decide which one you need to put the code with this lifecycle :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@WrathChaos: What if I want to call both shouldComponentUpdate and componentWillReceiveProps both?
If I will implement shouldComponentUpdate using React.memo then the order will be
shouldComponentUpdate -> componentWillReceiveProps
but ideally, in class-based components, componentWillReceiveProps should get called before shouldComponentUpdate