From the course: Learning Full-Stack JavaScript Development: MongoDB, Node, and React
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Rendering a list of items
From the course: Learning Full-Stack JavaScript Development: MongoDB, Node, and React
Rendering a list of items
- We created a mock API endpoint, configured express to use it and allow cross origin requests to it. And we're fetching this mock API endpoint right here before we render the React application. How do we use this data in React? We have options. We can delay the rendering of the app until we have the data. Let's start with that option. All we need to do for that is move this route dot render call to the Axios promise handler because in here, we're done with the network call and we have the data. To make the app component aware of that data, we can pass it as props. Let me pass it here as an object. Name it initial data expression to pass in a dynamic value. And in here I'll pass in an object with contests coming from response.data. The mocked API call we created returns an array of contests directly. I like to have the API calls always return an object with named elements. So, instead of returning contests…
Contents
-
-
-
-
-
Creating a mock API endpoint5m 52s
-
(Locked)
Using an API endpoint from the browser9m 2s
-
(Locked)
Rendering a list of items8m 47s
-
(Locked)
React’s key for items in a list4m 29s
-
(Locked)
Fetching data while React is rendering8m 5s
-
(Locked)
Server-side rendering of the root path7m 41s
-
(Locked)
Sharing data between server and client5m 1s
-
(Locked)
Fetching data from MongoDB6m 17s
-
-
-