Setting component state
In this section, you're going to write some React code that sets the state of components. First, you'll learn about the initial state—this is the default state of a component. Next, you'll learn how to change the state of a component, causing it to re-render itself. Finally, you'll see how new state is merged with existing state.
Initial component state
The initial state of the component isn't actually required, but if your component uses state, it should be set. This is because if the component JSX expects certain state properties to be there and they aren't, then the component will either fail or render something unexpected. Thankfully, it's easy to set the initial component state.
The initial state of a component should ...
Get React and React Native now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.