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.
We'll cover the following...
We'll cover the following...
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 ...