0
Challenge · 60Routing & Data
URL State
Coreused in ~55% of apps
Your teammate pings you: "the bug only happens on the photos tab with the city filter and the third item open." You reproduce it, hit refresh, and it all vanishes — because that whole view lived in useState. The fix isn't a new hook, it's a decision: that state describes what the user is looking at, so it belongs in the URL.
Core idea. Some UI state describes "what view am I looking at" (tab, filter, sort, page, selected item, query) — that state belongs in the URL so it is shareable, bookmarkable, reloadable, and Back-able; truly ephemeral state (an open dropdown, hover, an in-progress text field) stays in useState.
poke it, drag it,
try to break it
try to break it
no slides here.
you drive.
you drive.
Playground, this isn't a screenshot
BACK THIS UI WITH
gallery.app/g?tab=photos&filter=sky&item=1
encodes viewfilter
This gallery has a tab, a filter, and a selected item. Flip the backing store, then try Reload, Share, and Back.
↑ play a little first, then dig in