Chapter 6. Routing and State Management
Every web application, no matter how sophisticated its architecture or how clever its rendering strategy, ultimately boils down to two questions: what is the user looking at, and what data does the application need to show it? The URL answers the first question, and routing is how your application reads it. State management answers the second.
These two concerns are deceptively simple on their own. Developers learn routing in an afternoon. State management takes a bit longer, mostly because there are many competing libraries and everyone on the internet has a strong opinion about which one you should use. But the real complexity isn’t in routing or state management individually. It’s in the space between them.
The URL is state that lives outside your application. It’s visible in the address bar, shareable, bookmarkable, and indexed by search engines. Some of your application’s state belongs there, like filters, pagination, and the selected tab. Some of it absolutely doesn’t, for example, whether a dropdown is open or what the contents of a form are before submission. Getting that boundary wrong creates bugs that are hard to diagnose: the back button undoes things it shouldn’t, shared links don’t show what the sender intended, or the URL says one thing while the page shows another.
In Chapter 3, we explored where to draw boundaries between client and server, and we touched on the tension between persistent and ephemeral state. In Chapter 4 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access