โ† All React Flashcard Decks

useRef and useMemo Flashcards

6 cards from real React practice questions. Tap to flip, then mark Knew It or Still Learning โ€” missed cards come back until you master them.

Read the first 6 useRef and useMemo flashcards as text
  1. What is a common use case for useRef that does NOT involve DOM access?

    Answer: Storing the previous value of a prop or state

    Storing a previous value in a ref lets you compare current and previous values without triggering re-renders.

  2. What hook is semantically related to useMemo but applies to functions instead of values?

    Answer: useCallback

    useCallback memoizes a function reference so it only changes when its dependencies change, analogous to useMemo for values.

  3. Why is over-using useMemo considered an anti-pattern?

    Answer: Memoization itself has overhead; the benefit only justifies complex computations

    Every useMemo call has bookkeeping cost, so memoizing simple or fast operations can be slower than recomputing.

  4. How can useRef help avoid stale closures in event handlers?

    Answer: By storing the latest value in ref.current so the handler always reads up-to-date data

    Storing the current value in a ref lets an event handler read the latest value without being recreated on every render.

  5. Will useMemo run during server-side rendering (SSR)?

    Answer: Yes, it runs on both server and client

    useMemo runs during SSR just like on the client, though React does not guarantee caching between server requests.

  6. What does React do with the value returned by useMemo when the component unmounts?

    Answer: It is garbage collected along with the component

    The memoized value is part of the component's fiber and is garbage collected when the component unmounts.

Written and edited by , founder of Practice Test Geeks, with AI assistance. We have not yet matched this exam's facts to an official source, so confirm fees, dates and rules with the exam body. Editorial policy