How to implement componentWillUnmount using react hooks?

Posted by Andre Scott | Updated on

Want to implement componentWillUnmount using react hooks? You can make use of useRef and store the props to be used within a closure such as render useEffect return callback method.

However a better way is to pass on the second argument to useEffect so that the cleanup and initialisation happens on any change of desired props


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

Related Questions & Answers