How to use setState callback on react hooks?

Posted by Jessica Taylor | Updated on

Want to use setState callback on react hooks? React 16.8 introduced Hooks which gave us a way to add state to functional components through the useState Hook. However, the useState Hook does not have a second callback argument. Instead, we use the useEffect Hook and its second argument, which is an array of dependencies.

You need to use useEfect hook to achieve this:


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