QuizNot attempted
useRef for a DOM node (React 19 types)
1–4 to choose, Enter to submit
Show answer & explanation
Correct answer:
RefObject<HTMLInputElement | null>:currentisnulluntil React attaches the node (and after unmount)
- Passing
nulltouseRef<HTMLInputElement>picks theuseRef<T>(initialValue: T | null): RefObject<T | null>overload, socurrentis honestlyHTMLInputElement | nulland must be narrowed - React 19 also made
RefObject.currentmutable and deprecatedMutableRefObject. - Not RefObject<HTMLInputElement> with a readonly current: that was the React 18 typing for this call.
- Not MutableRefObject<HTMLInputElement>: that is deprecated, and the node really is
nullbefore mount. - Not HTMLInputElement:
useRefalways returns a{ current }box.