How to set focus on input after render in React?

Posted by Prem Tiwari | Updated on

Want to set focus on an input element after it is rendered? In this answer, I have shared how to set focus on input after render in React.

You should do it in componentDidMount and refs callback instead. Something like this:

Add the following code in your HTMl page:


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