This chapter covers
- Asking React to manage component state values by calling useState
- Changing state values and triggering re-renders with an updater function
- Using the previous state to help generate new state values
- Managing multiple pieces of state
- Considering how React and components interact to persist and update state and synchronize state and UI
If you’re building React apps, you’re expecting the data your app uses to change over time. Whether it’s fully server-rendered, a mobile app, or all in a browser, your application’s user interface should represent the current data, or state, at the time of rendering. Sometimes multiple components throughout the app will use the data, and sometimes a component doesn’t need to share its secrets and can manage its own state without the help of mammoth, application-wide, state-store behemoths. In this chapter, we keep it personal and concentrate on components taking care of themselves, without regard for other components around them.