Question presented to candidate: "React 19 changed how refs work. What changed, and what does it mean for existing code?"
What a strong answer should cover:
refis now a regular prop for function components. You destructure it like any other;forwardRefis no longer needed for the common case.forwardRefstill works and was not removed — verified, it emits no deprecation warning in 19.2.8. Existing code keeps running.- Ref callbacks may return a cleanup function. React calls it on detach instead of invoking the callback a second time with
null. - Why that matters: the old null-call pattern made it awkward to pair setup with teardown, and easy to leak an observer or listener attached in a ref callback.
- The old behaviour is still supported for callbacks that return nothing, so existing ref callbacks are unaffected.
- Practical effect: fewer wrapper layers, simpler TypeScript generics, and a component tree without
ForwardRef(...)nodes. - Still true:
refon a function component only works if that component does something with it, andkeyremains a non-prop. - Migration: a codemod exists; there is no urgency since
forwardRefstill functions.
Clarifying questions expected:
- "Are we on React 19 already, or planning the upgrade?"
- "Is this a library that must support React 18 as well?" — that decides whether you can drop
forwardRef.
Code / implementation expected: Yes — the same component before and after, plus a ref callback with a cleanup.