Command Palette

Search for a command to run...

Hectal
Phase 13: Routing
React · Exercise 3 of 6 PreviousNext
Intermediate

Filters in the URL

Make the three buttons filter the list using search params, not useState: #veg sets ?type=veg, #fruit sets ?type=fruit, and #all removes the type param completely.

The list shows only items whose type matches, or all items when there's no type. The address bar (#address) already shows pathname + search.

What Check tests

  1. At the start all four items are listed
  2. Vegetables shows only Carrot and Spinach and puts type=veg in the URL
  3. Fruit shows only Apple and Mango
  4. All shows every item and removes type from the URL
  5. The filter comes from the URL, not useState

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.