How to access refs of child component in ReactJS?

Posted by Jessica Taylor | Updated on

If you want to access refs of child component in ReactJS? Accessing the refs of a child breaks encapsulation since refs are not considered part of a component’s API. Instead you should expose a function on Inner that can be called by a parent component, calling it focus might make sense.

Also, focus the element in componentDidUpdate to ensure rendering is complete:


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