课程: Learning Full-Stack JavaScript Development: MongoDB, Node, and React

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Rendering a list of items

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…

内容