Accessing a Child Component
React provide a way to access to a child's DOM node from a parent component by using Refs
.
For examples:
Assume that you want to put the cursor in the user name fields when the page render.
In child component, we create Refs
by using React.createRef()
and then attached to React elements via the ref
attribute.
In the parent component, we can get a reference to the Input component and call its focus()
method.