I have a doubt , when we are using react component methods there are methods with same behavior, and also they are called one by one in the component life cycle ? then what is the major difference,
shouldComponentUpdate(nextProps, nextState){
// It will be executed with nextProps and nextState
}
componentWillUpdate(nextProps, nextState){
// It will be executed first with same data nextProps, nextState
}
In the above example We have same parameter data with same behavior but the shouldComponentUpdate will be called first.
Then what is the main difference ?
The function ComponentWillUpdate will be executed, if function shouldComponentUpdate returns true.
If shouldComponentUpdate returns false, then ComponentWillUpdate will not be called.
Here is document of 2 functions : componentwillupdate and shouldcomponentupdate.
You can read here component-lifecycle
I hope it's helpful to you.
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