Loading…
A short voice session: one question, one follow-up, then instant feedback — up to 5 minutes.
In React 19 a function component can accept ref as a regular prop and attach it to an element; useImperativeHandle exposes a small custom API, such as focus(), instead of the raw DOM node.
Before React 19, a component had to be wrapped in forwardRef to receive a ref. In React 19, ref is passed like any other prop: function TextInput({ ref, ...props }) { return <input ref={ref} {...props} />; }. Sometimes you do not want callers to manipulate the whole DOM node; useImperativeHandle(ref, () => ({ focus, clear })) lets the child expose only specific methods. Imperative handles should be reserved for things that are hard to express with props, such as focusing, scrolling or triggering animations, not for passing data.