From the course: Building React and Django Apps

Unlock the full course today

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

Connecting a React component to a service

Connecting a React component to a service

From the course: Building React and Django Apps

Start my 1-month free trial

Connecting a React component to a service

- [Instructor] In the service API we already created the createBooking method. However, when we connect it to the checkout page component, we need to pass back any validation errors that happen. We can do this by adding reject to the promise, and by catching any errors returned from the API, and then passing them back. On the checkout page, we can keep track of whether or not the order was placed. We create the constructor in order to have the orderPlaced field as part of our state. And then we define the placeOrder method which will call back up to the app context, to actually place the order. And then when it is completed, we update the state. And the same is true if there are validation errors. We update the state again, but this time the order is not placed if there are any errors in the form. Now in the render method of the checkout page, we're going to need that data. And right before we create any form fields,…

Contents