Command Palette

Search for a command to run...

Hectal
Phase 16: Performance
React · Exercise 3 of 5 PreviousNext
Intermediate

Cache an expensive filter with useMemo

filterProducts logs filtering each time it runs. Right now it runs on every render, including when you click #theme, which has nothing to do with the products.

Use useMemo so filtering runs only when the minimum price changes. Clicking #theme must not log filtering.

The #min select chooses a minimum price; #count shows how many products match, like 3 products.

What Check tests

  1. All 5 products show at first
  2. Toggling the theme doesn't filter again
  3. Choosing ₹100 and up shows 3 products and filters once
  4. Uses useMemo

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

Runs in your browser. Your code is saved here.

Your page

Press Run to see the page.

Console

Nothing logged yet.