From the course: Learning React Native

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Collecting input

Collecting input

From the course: Learning React Native

Start my 1-month free trial

Collecting input

- [Instructor] In the last lesson, we constructed the user interface for our form. In this lesson, we're going to make the form work by collecting the user input and adding it to our list of colors. We're going to create a controlled form component. And what that means is React is going to control the state of our form. So we'll need the useState hook. We'll save the current input value in state. So the useState hook is going to give me the input value and a function to change that value. At first, the input value will be an empty stream. So I'm going to come down here to the text input and add the input value to the value property. Now when the user changes the value, we're going to go ahead and capture that change using the onChange text property. This property is a function, and it will pass the current value of the text input to the function as an argument. We'll send this text to the setValue function which will…

Contents