A function component is a JavaScript function that accepts props and returns JSX markup. It is the modern approach used to build React components. section 8.3
A practical function component can:
- Store state with useState, such as loading status and fetched data. section 8.3
- Fetch asynchronous data inside useEffect and update state when the Promise resolves. section 8.3
- Render different markup conditionally, showing Loading... before displaying a Charts component. section 8.3
Data-loading App component
App initializes loading to true, fetches JSON in useEffect, stores the result with setData, then passes data to Charts after loading finishes.
