useRef
Test your knowledge of the useRef hook in React with this quiz.
20 questions · free · answers explained
All questions in this quiz
- What does useRef return?
- Which value is a good candidate to store in a ref?
- How does a ref differ from a regular variable declared inside a component?
- What happens when application code changes ref.current?
- Why is a ref for a DOM element commonly initialized with null?
- When should application code generally read or write ref.current?
- How do you connect a ref object to an input DOM element?
- How can a click handler focus an input referenced by inputRef?
- What does React do to a DOM ref when its element mounts and later unmounts?
- A value must update the text displayed by a component. Where should it usually be stored?
- How can a component remember the previous value of a prop without causing another render?
- Why might an interval ID be kept in a ref?
- How is the initialValue argument passed to useRef handled?
- Which pattern avoids recreating an expensive object on every render when storing it in a ref?
- What can happen to refs when Strict Mode calls a component twice during development?
- Why is ref.current usually not a useful Effect dependency?
- What argument does React pass to a callback ref when a DOM node is attached or removed?
- What is a suitable approach for keeping references to a dynamic list of DOM nodes?
- In React 18, how can a function component expose one of its DOM nodes to a parent ref?
- What does useImperativeHandle let a component do with a forwarded ref?
Prefer to read first? React interview questions with written answers.