Expose a controlled imperative API to a parent ref.
Section: Context and Ref Hooks
useImperativeHandle custom ref API
tsx
tsx
useImperativeHandle(ref, () => ({
focus: () => inputRef.current?.focus(),
clear: () => setValue(''),
}), []);Explanation
Use with `forwardRef` when a parent truly needs an imperative child API.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing Context and Ref Hooks
useRef mutable container
Persist mutable values between renders without re-rendering.
useId for stable accessible IDs
Generate stable IDs for labels and ARIA relationships.