State
The last major topic we need to cover in regards to the React library is the state object. We already learned that we use the props objects to pass data from one component to another. However, we can't just hardcode our data in a production-level application like we did in the Props section. The musical instruments' product information needs to be obtained from somewhere, and not hardcoded in our React code. In a real application, the data should come from a server-side API. However, for the purpose of this chapter, we'll obtain the product information from a JSON file called cards.json. In React, our application data needs to live inside the state object.
Let's take a look at how to initialize and set our state object in the next ...
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