How to use ComponentDidUpdate?
There are many methods in React for different purposes. ComponentDidMount(), componentDidUpdate() etc. ComponentDidUpdate is a method of component lifecycle. It is called after any props or stats are updated. It can be used to update anything after a state update. ComponentDidUpdate() is called after ComponentDidMount(). It takes two arguments: the first argument will be the previous props, second :previous state. Inside the method you can specify the condition to be checked. Here is an example.
componentDidUpdate(prevProps, prevState) { if (prevState.pokemons !== this.state.pokemons) { console.log('pokemons state has changed.') } }
To see where to use componentDidUpdate() lets see a case in which it is used. When you are using a third party API on a condition where the previous state and current state have changed. The API will be called if the state is changed. The API call will be stated inside the conditional statement.
sam smith
16 Apr 2023
I just want the whole world to know about this spell caster I met two weeks ago, I cannot say everything he has done for me my wife left me 3 years ago left with my kids I was going through online when I meant this wonderful man's testimony online I decided to give it a try and my wife is back to me now and we are happily married again cause is too much to put in writing all I can say is thank you very much am very happy Contact him today on oseremenspelltemple@gmail.com or whatsapp him on +2348136482342. www.facebook.com/Dr-odion-spell-temple-110513923938220