Course lesson

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

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.

Duration
1 min
Access
Free
Transcript
Available

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.