From the course: Interactive React for the Web
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Posting a new message to the API - React.js Tutorial
From the course: Interactive React for the Web
Posting a new message to the API
- [Instructor] In this video, we're going to connect the post form component to the API. Adding a submit handler that will post new status messages using the built in Fetch API. We're going to start by going down to the post form component. Currently, the form doesn't have anything at all, so it's just going to reload the page. Let's add an "on submit" to this and we're going to create a new helper called, "post status update." You just define it right here. That's going to get a submit event. So we'll prevent the default action on that one. And now we can build up the data that we're going to send to the API. We'll start by creating a status object to post. So we'll say this is going to be our new status message and this will be an object. We'll take a look at the fields in the API returns. So we have ID, we're going to let that be set automatically. And then we have the message, the type, and the time. So we'll pass all three of those here. The message, of course, will be our…
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)
Consuming live data using a REST API2m 14s
-
(Locked)
Inspecting the starting code5m 41s
-
Making our first API call in a useEffect hook6m 50s
-
(Locked)
Providing feedback via conditional rendering6m 53s
-
(Locked)
Wiring up the status form to post an update3m 17s
-
(Locked)
Posting a new message to the API7m 50s
-
(Locked)
Lifting state to make data usable throughout the app6m 9s
-
(Locked)
Update the message list from local state after posting4m 41s
-
(Locked)
Breaking a large file into separate components9m 43s
-
(Locked)
Solution: Make the date and time editable5m 18s
-
(Locked)
-