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
From the course: Building React and Django Apps
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,…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
Handling creating models with Django REST framework1m 39s
-
(Locked)
Creating a REST API Service class with React and Axios2m 24s
-
(Locked)
Creating a basic form as a React component2m 22s
-
(Locked)
Creating form fields for basic form2m 6s
-
(Locked)
Connecting a React component to a service2m 26s
-
(Locked)
Validating form data with Django REST framework54s
-
(Locked)
Displaying validation errors with React1m 23s
-
(Locked)
-
-
-