Recall & Review
beginner
What is the purpose of the
useMemo hook in React?The
useMemo hook helps to remember (or memoize) a value so React does not have to recalculate it on every render, improving performance.Click to reveal answer
beginner
How do you use
useMemo to optimize a slow calculation?Wrap the slow calculation inside
useMemo(() => slowCalculation(), [dependencies]). React will only recalculate when dependencies change.Click to reveal answer
intermediate
What happens if you pass an empty dependency array
[] to useMemo?The memoized value is calculated once on the first render and never recalculated again, unless the component unmounts and remounts.
Click to reveal answer
intermediate
Can
useMemo replace useState or useEffect?No.
useMemo only memoizes values. useState manages state, and useEffect runs side effects. They serve different purposes.Click to reveal answer
intermediate
Why should you not overuse
useMemo?Because memoization itself has a cost. Use it only when a calculation is expensive and the saved work improves performance noticeably.
Click to reveal answer
What does
useMemo return?✗ Incorrect
useMemo returns the memoized value from the function you provide.When does
useMemo recalculate the memoized value?✗ Incorrect
It recalculates only when one or more dependencies in the array change.
Which of these is a good use case for
useMemo?✗ Incorrect
useMemo is best for expensive calculations that depend on props or state.What happens if you omit the dependency array in
useMemo?✗ Incorrect
Without dependencies, React recalculates the value every render, so memoization is ineffective.
Which hook is best to run side effects, not memoize values?
✗ Incorrect
useEffect is designed to run side effects like data fetching or subscriptions.Explain how
useMemo helps improve React app performance.Think about when React re-renders and how <code>useMemo</code> saves work.
You got /4 concepts.
Describe the difference between
useMemo and useEffect.One remembers values, the other runs code after render.
You got /4 concepts.