React · Senior · Question 16 of 75
What is useImperativeHandle for?
- ✓Correct answer: To expose a limited set of methods to the parent via ref instead of a DOM node
- 2To call a child component's methods without a ref, by component name
- 3To synchronously update parent state from a child component's effect
Explanation
useImperativeHandle(ref, () => ({ focus, scrollToBottom })) exposes only the needed methods and hides implementation details. An imperative API is an exception for focus, scrolling, animations and media, not a replacement for props.