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

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…

Contents