Command Palette

Search for a command to run...

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

Make memo work with a stable callback

The list items are wrapped in memo, but each still re-renders when you click #bump (the visit counter), because App passes a new onRemove function on every render. Each item logs Item rendered: <name>.

Fix it so clicking #bump doesn't re-render any item, while the Remove buttons (class remove) still delete the right item.

Use useCallback (with the updater form of the state setter, so the callback needs no dependencies).

What Check tests

  1. Three items are shown
  2. Clicking Visits re-renders no item
  3. Remove deletes the right item
  4. Removing again still works (no stale list)
  5. Uses useCallback

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.