useRef

Test your knowledge of the useRef hook in React with this quiz.

20 questions · free · answers explained

Start the quiz

All questions in this quiz

  1. What does useRef return?
  2. Which value is a good candidate to store in a ref?
  3. How does a ref differ from a regular variable declared inside a component?
  4. What happens when application code changes ref.current?
  5. Why is a ref for a DOM element commonly initialized with null?
  6. When should application code generally read or write ref.current?
  7. How do you connect a ref object to an input DOM element?
  8. How can a click handler focus an input referenced by inputRef?
  9. What does React do to a DOM ref when its element mounts and later unmounts?
  10. A value must update the text displayed by a component. Where should it usually be stored?
  11. How can a component remember the previous value of a prop without causing another render?
  12. Why might an interval ID be kept in a ref?
  13. How is the initialValue argument passed to useRef handled?
  14. Which pattern avoids recreating an expensive object on every render when storing it in a ref?
  15. What can happen to refs when Strict Mode calls a component twice during development?
  16. Why is ref.current usually not a useful Effect dependency?
  17. What argument does React pass to a callback ref when a DOM node is attached or removed?
  18. What is a suitable approach for keeping references to a dynamic list of DOM nodes?
  19. In React 18, how can a function component expose one of its DOM nodes to a parent ref?
  20. What does useImperativeHandle let a component do with a forwarded ref?

Prefer to read first? React interview questions with written answers.