10 Managing state
This chapter covers
- Persisting application state in memory
- Coordinating state across multiple components
- Organizing application state
- Persisting application state using browser local storage
State management is always a hot topic in SPA applications. But what is state? Well, state can be thought of as the sum of all data held by a system at any given point in time. We've already seen lots of examples of state in previous chapters. Anywhere we've created a field or property on a component to store a value is state. Users of an application alter state all the time by performing actions within the system. They might click a button which increments a counter or enter values in a form which trigger validation.
Sometimes user actions might alter state, which has consequences across multiple components. A good example of this is when a user adds an item to their cart on Amazon. The basket automatically updates to show the number of items it's currently holding. This is when state management comes into play.