Refs in React

React’s ref attribute allows React component to access underlying DOM node. Since ref needs a backing instance it won’t work with functional components.

Besides strings, refs also support a callback that gets called after the component is mounted so you can do some initialization there.


With string:

<input type="text" ref="input" />


// Access in the component

With callback:

<input type="text" ref={element => element.focus()} />