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
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.
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.
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.
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.
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.
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 Nathan Beja, 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