More Hooks
useRef
useRef holds a value that survives re-renders without causing one. It is most often used to reach a DOM element directly.
import { useRef } from "react";
function SearchBox() {
const inputRef = useRef(null);
return (
<>
<input ref={inputRef} placeholder="Search..." />
<button onClick={() => inputRef.current.focus()}>Focus</button>
</>
);
}