useRef
Returns a mutable ref object whose .current property is initialized to the given argument. Does not cause re-renders.
Syntax
react
const ref = useRef(initialValue)Example
react
function FocusInput() {
const inputRef = useRef(null);
const focusIt = () => inputRef.current.focus();
return (
<>
<input ref={inputRef} />
<button onClick={focusIt}>Focus</button>
</>
);
}