The useRef Hook
useRef holds a mutable value that survives renders without causing one. It also gives access to DOM nodes.
Example
function Focus() {
const ref = useRef(null);
return (
<>
<input ref={ref} />
<button onClick={() => ref.current.focus()}>Focus</button>
</>
);
}Exercise
Read the stored value.
ref.Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.