Last active
October 16, 2019 13:04
-
-
Save ahmadabdul3/e58a835dec920dd5de8948f28838fc8a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SomeForm extends Component { | |
state = { | |
email: '', | |
password: '', | |
}; | |
// - using arrow functions will auto-bind to 'this', so no need | |
// for doing this.updateFormField = this.updateFormField.bind(this) | |
// in the constructor (although there are some caveats to this | |
// approach when writing unit tests) | |
updateFormField = (e) => { | |
const { name, value } = e.target; | |
this.setState({ [name]: value }); | |
}; | |
submit = (e) => { | |
const { email, password } = this.state; | |
// submit the form... | |
}; | |
render() { | |
const { email, password } = this.state; | |
return ( | |
<form onSubmit={this.submit}> | |
<input value={email} name='email' onChange={this.updateFormField} /> | |
<input value={password} name='password' onChange={this.updateFormField} /> | |
</form> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment