From the course: React for Web Designers

Unlock this course with a free trial

Join today to access over 22,500 courses taught by industry experts.

Let form post to the API

Let form post to the API - React.js Tutorial

From the course: React for Web Designers

Let form post to the API

- [Narrator] In this video, we're going to connect the post form to the API, adding the submit handler that will post new status messages. Over here in my post form component, I'm going to scroll down to the form field. And we're going to add an on submit handler. That way, however we submit the form, our handler will be triggered. We'll call this post status update. It's a function we're going to need to define. And to save having to watch me do a lot of typing here, I've included a snippet in the exercise files for this video with all the code that we can copy and paste, and then we'll talk through what it's doing. So, we'll paste that in. So this is an event handler that takes an event as its argument. First we prevent the default actions so the page doesn't reload when we submit the form. And we create a new status object. This takes the message text and type from our form state and saves them to fields called message and type, which are what the API uses. And then we are…

Contents