Ref a DOM Element

In this lesson, we'll learn how to interact with DOM nodes in React.

Why interact with the DOM?

Sometimes you need to interact with your DOM nodes in React. The ref attribute gives you access to a node in your elements. That is usually an anti pattern in React, because you should use its declarative way of doing things and its unidirectional data flow. We learned about it when we introduced the first search input field, but there are certain cases where you need access to the DOM node.

The official documentation mentions three:

  • to use the DOM API to manage focus, media
...