From the course: React: Components, Context, and Accessibility

Unlock the full course today

Join today to access over 24,900 courses taught by industry experts.

Controlled components

Controlled components

- [Narrator] We just looked at uncontrolled components and how we can use refs to capture values from inputs. In this video, we'll look at controlled components. A controlled input accepts a value as a prompt and also uses a call back to change a value. So, let's make some adjustments to our form here. Right now, we have our handleSubmit function, let's stub out a few more things that we're gonna need. So the first thing here is state. So, our state property is going to have a value called Message, and the initial state will be just an empty string. Next, we want to create something called handleChange. And handleChange is gonna be another function that does something in a second. So, we looked at how to add a ref to an input, let's actually get rid of this though. Instead, we're going to use the value this.state.message, and then when something changes, we're going to call this.handleChange. Okay, so let's create our…

Contents