Changing of Values
Learn how states are modified and controlled in various HTML elements.
We'll cover the following...
If a value is modified, as is the case with text inputs and radio buttons, the corresponding React state is set to the value provided by the user, triggered by the onChange
event. Controlled components now mandate the following procedure:
- When the user inputs text, the value changes.
- The
onChange
event is triggered and processed by the event handler. - The event handler sets the state using the new value.
- React re-renders the user interface and sets
this.state
to the new value. - The user sees their newly provided value on the screen.
This looks normal to the user, and they will not notice that the form works differently behind the scenes and does not reflect usual browser behavior. React fully takes care of the logic in the background and paints a new frame in the user interface.
...