From the course: React for Web Designers
Unlock this course with a free trial
Join today to access over 22,600 courses taught by industry experts.
Bring form fields under control - React.js Tutorial
From the course: React for Web Designers
Bring form fields under control
- [Instructor] Now we need to start wiring up this post form so it can send updates to the API. We'll take this in two pieces. First, the form is currently uncontrolled, so we can type in it all we want, and React does not notice. We'll handle that in this video. The second part, we'll be taking action when the form is submitted. Over here in hotel.js, here is my post form component, and here are my form fields. So the first thing that I'm going to do is add a little bit of state to hold the values of those fields. So we'll have one called message text, which will have set message text to go with it, and these will come from React.usestate, and the initial value for message text will be an empty string. We'll call React.usestate again. This time it will be for the message type, that select box. Set message type and the initial value will be this default type that we saved earlier. Now we need to update our form fields. We'll start with the text area. This will need an on change…
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)
Use live data from a RESTful API4m 40s
-
(Locked)
Inspecting your starting React code5m 9s
-
(Locked)
First API call with useEffect hook5m 10s
-
(Locked)
Using conditional rendering4m 36s
-
(Locked)
Bring form fields under control3m 3s
-
(Locked)
Let form post to the API3m 25s
-
(Locked)
Lifting state for data visibility2m 48s
-
(Locked)
Completing the status updater3m 20s
-
(Locked)
-