URL as State (Search Params and Routing State)
Learn when to store UI state in the URL instead of component state, and how it improves shareability and persistence.
Some UI state — the current page number, an active filter, a selected tab, a search query — represents something the user would reasonably expect to survive a page refresh or be shareable via a link. Storing that state purely in useState loses it on refresh and can't be shared, while storing it in the URL (as a path segment or query parameter) makes it durable and linkable for free.
Storing state in the URL is like writing your current progress on a bookmark you leave in a book instead of just remembering the page number in your head — anyone can pick up the book (open your link) and land exactly where you left off, and the bookmark survives even if you put the book down and pick it up again later.