Search IOCombats

Search challenges, guides, questions and articles

UseRef Interview Questions

5 curated useref interview questions with detailed answers and examples.

← Browse all interview questions

Use useRef to create a mutable reference that React attaches to a DOM node after mount. Access the node via ref.current inside useEffect, not during render. Use callback refs to measure elements and forwardRef to expose a child component's DOM node to a parent.

intermediateadvanced hooks-and-patternsreactuseRefdom manipulation

A controlled component has its value driven by React state. An uncontrolled component lets the DOM own the value, read via a ref on submit. Controlled enables real-time validation and formatting. Uncontrolled is mandatory for file inputs and is used by React Hook Form for performance.

intermediateadvanced hooks-and-patternsreactformscontrolled components

Use forwardRef with useImperativeHandle to expose imperative methods from a child component, or use controlled props to manage disabled state from the parent.

intermediatecomponent communicationreactuseRefforwardRef

Controlled components let React own the input value through state. Uncontrolled components let the DOM own the value and read it via refs. Know when each is appropriate.

intermediateforms and-inputsreactcontrolled componentsuncontrolled components

Implement a character counter for a textarea using a controlled input. Understand why the counter should be derived state, not stored state, and when useRef is the right tool instead.

intermediateforms and-inputsreacttextareacharacter counter