Skip to content

Commit

Permalink
Remove misleading example in Forms (#2875)
Browse files Browse the repository at this point in the history
* Remove misleading example in Forms

* Update forms.md

* Update forms.md
  • Loading branch information
gaearon authored Apr 1, 2020
1 parent 7551fdf commit fa5e6e7
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions content/docs/forms.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,7 @@ class NameForm extends React.Component {

Since the `value` attribute is set on our form element, the displayed value will always be `this.state.value`, making the React state the source of truth. Since `handleChange` runs on every keystroke to update the React state, the displayed value will update as the user types.

With a controlled component, every state mutation will have an associated handler function. This makes it straightforward to modify or validate user input. For example, if we wanted to enforce that names are written with all uppercase letters, we could write `handleChange` as:

```javascript{2}
handleChange(event) {
this.setState({value: event.target.value.toUpperCase()});
}
```
With a controlled component, the input's value is always driven by the React state. While this means you have to type a bit more code, you can now pass the value to other UI elements too, or reset it from other event handlers.

## The textarea Tag {#the-textarea-tag}

Expand Down

0 comments on commit fa5e6e7

Please sign in to comment.