Browse Source

Remove misleading example in Forms (#2875)

* Remove misleading example in Forms

* Update forms.md

* Update forms.md
main
Dan Abramov 5 years ago
committed by GitHub
parent
commit
fa5e6e7a98
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      content/docs/forms.md

8
content/docs/forms.md

@ -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}

Loading…
Cancel
Save