React Refs and Imperative Handles Quiz
Three drills on using refs to reach into the DOM, forwarding a ref through a wrapper component, and using useImperativeHandle to expose a controlled API.
Question Bank
Medium
JavaScript
3 questions
quiz
react
references
hooks
222 views
2
Use a ref to focus an <input> programmatically on mount. Why are refs the right tool here instead of state?
A parent wants to focus an <input> that lives inside a custom <TextField> component. Use forwardRef so the parent's ref reaches the underlying input.
Use useImperativeHandle to expose a controlled API (focus, clear) from <TextField> instead of leaking the raw DOM node. Why is this safer than handing out the input directly?
