From the course: Building React and ASP.NET Core Applications

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Reading data from React

Reading data from React

From the course: Building React and ASP.NET Core Applications

Start my 1-month free trial

Reading data from React

- [Instructor] So we created a table. Now let us get the data from the web API endpoint, then show them in that data. For that, let's go to Visual Code. In here, go to ClientApp, then source, components, Trip, and the Trips file. To get the data from the API endpoint, we are going to use one of the lifecycle methods, and that is going to be componentDidMount. What this means is that we are going to send a request to get all the trips once the UI has been loaded, so once the component was mounted. In here, let us write: this.populateTripsData. Now let's create this method, so populateTripsData. Now what we want to do in here is that we want to send a get request to our API endpoint. And once we have a result with a list of trips, we want to change the state of trips to that result. And to send HTTP requests to our API endpoints, we are going to use a library named Axios. So, for that, let's install it first. So…

Contents