Creating strongly-typed refs in function components

In this lesson, we learn how to get a strongly-typed reference to an element in a function component.

Understanding the useRef hook

The useRef hook can be used to access all the properties and methods of an element.

const element = React.useRef(null);
// can access all the properties and methods of `element` via `element.current`

...
return (
  <SomeComponent ref={element} />
);

It is commonly used when we need to invoke methods on an element imperatively.

Get hands-on with 1400+ tech skills courses.