Focus an input field in React with the `useRef` and `useEffect` hooks

Share this video with your friends

Send Tweet

In this lesson, we make the Search input field focus on page load. To do this, we keep a reference of the input field with the useRef hook, and trigger focus on that field when the component mounts with another React hook, useEffect.