Handling user input – Input, TextArea, and Select
Handling React form elements is slightly different from the way non-React applications handle user inputs. In this section, we will look at common form elements that are used in handling user input while following React best practices.
Input
Input fields in the form are the most widely used tags in any web application. An input field allows the collection of user data. Input fields have different types depending on their purpose in a form. In the controlled input form element, the component state is always set using a value or checked attribute on the form input field. You also have a callback that listens to the change in value as a result of user input.
With the input type radio and checkbox, we use the checked attributes. To access the value of the input field, we can use event.target.checked
.
TextArea
Textarea
is a tag that allows users to write multi-line characters of text. Textarea
is usually used to collect...