practicebasic
Derive lists with useMemo
A task list is filtered and sorted on every render — even when only an unrelated counter changes. Use useMemo so the expensive calculation only repeats when query or order change.
Objectives
- 1.Wrap the filtering + sorting in useMemo
- 2.Declare [query, order] as dependencies
- 3.Verify in the console that filtering does not re-run when the counter changes
your code
Hint
useMemo(fn, [deps]) memoizes the value returned by fn. It only recalculates when a dependency changes. If the computation is expensive or produces a new array on every render, useMemo prevents cascading re-renders.
Related concepts
Was this helpful?
Sign in to give feedback
