Form handling is a little bit different with React. An HTML form will navigate to the next page when it is submitted. Oftentimes, we will want to invoke a JavaScript function that has access to form data after submission and avoid navigating to the next page. We already covered how to avoid using submit in the previous section using preventDefault().
Let's first create a minimalistic form with one input field and the Submit button. In order to get the value of the input field, we use the onChange event handler. We use the useState hook to create a state variable called text. When the value of the input field is changed, the new value will be saved to the state.
The setText(event.target.value) statement gets the ...