React · Middle · Question 5 of 75
What is useMemo for?
- ✓Correct answer: Caching the result of an expensive computation between renders
- 2Keeping a value between page reloads
- 3Running side effects after render
Explanation
useMemo(() => filterTodos(todos, tab), [todos, tab]) recomputes the value only when dependencies change. The second use is a stable object reference for memo children or effect dependencies. React may discard the cache, so useMemo is an optimization, not a guarantee.