React hook useEffect dependency array

Posted by Jessica Taylor | Updated on

In this example, I have shared abut React hook useEffect dependency array. I would recommend you to write this as following example:

You can’t avoid the complexity of having a condition inside the effect, because without it you will run your animation on mount rather than just when changes. The condition also allows you to avoid animating when things other than change.

By including props.onAnimationComplete in the dependencies array, you avoid disabling the lint rule which helps ensure that you don’t introduce future bugs related to missing dependencies.


If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@] Your question and answer will appear on and help other developers.

Related Questions & Answers