arrow_backBACK TO DRILLS
Blue BeltusereflockPREMIUM

useRef Typed as MutableRefObject<undefined> Causes Type Error When Passed to DOM Ref Prop

A developer calls useRef() with no argument and passes the result to a div's ref prop in a TypeScript file.

REACT_MODULE // 0x42
const divRef = useRef();
return <div ref={divRef} />;

Why does TypeScript reject this, and what is the correct way to declare the ref?

lock

This Drill is Locked

This is a premium drill. Continue on to the next free drill in the sequence.