In the React lifecycle function shouldComponentUpdate(nextProps, nextState), nextProps is self explanatory.
But what does nextState do?
It doesn't sound right that I can evaluate upcoming state before even deciding if the component should be rendered/modified or not.
ReactJS shouldComponentUpdate() Method Return value: It by default it returns true and if it returns false then render(), componentWillUpdate() and componentDidUpdate() method does not gets invoked.
PureComponent overrides shouldComponentUpdate() lifecycle method. React. PureComponent implements shouldComponentUpdate() method to determine re-rendering with a shallow prop and state comparison for rendering performance optimization.
shouldComponentUpdate use to decide that changes in props or the state have affected to component output or not. componentDidUpdate will be triggered when there is an update on component output. shoudComponentUpdate take 2 arguments, nextProps and nextState . that contains a new update of props and state.
shouldComponentUpdate() Safe to use setState ? Yes! This method is called whenever there is an update in the props or state. This method has arguments called nextProps and nextState can be compared with current props and currentState .
Basically the state is already changed at that point and do you deem it necessary to rerender the component and based on that you return true or false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With