Refs provide a way to access DOM elements or React elements directly. They’re created with React.createRef
or useRef
and are commonly used to access input elements or store mutable values without triggering re-renders.
const inputRef = useRef(null);
function handleClick() {
inputRef.current.focus();
}
<input ref={inputRef} />