useMemo: Memoizing Expensive Calculations

Hands-on practice for this lecture. Work through the exercises and quizzes to reinforce what you've learned.

1

Exercise 1 of 1

Skip Expensive Work with useMemo

An expensive filter runs on every render — useMemo caches it so it only runs when the inputs change.

Store — filter runs on every render

Category filter

Unrelated state: 0

ProductList renders: 1

Showing 800 products in All — sorted by price

  • Product 780 — $11
  • Product 409 — $12
  • Product 427 — $12
  • …and 797 more

Click Tick. The filter re-runs even though the category didn't change — you may notice a slight delay. Click a category to see the filter actually do useful work.

Test Your Understanding

Multiple choice — select an answer to see the explanation.

1 / 4

What does useMemo return?