Created
April 28, 2018 21:18
-
-
Save MorenoMdz/13636cfc0673947e7393d520e1875eb4 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
/* Form on submit */ | |
<form onSubmit={(e) => { | |
e.preventDefault(); | |
const data = [...this.state.data, | |
this.state.inputText]; | |
this.setState({data, inputText: ''}); | |
}}> | |
<input | |
type='text' | |
name='inputText' | |
value={this.state.inputText} | |
onChange={(e) => { | |
this.setState({[e.target.name]: e.target.value}) | |
}} | |
/> | |
</form> | |
/** | |
* On form submit takes the event and prevent default behaviour | |
* then create a new array at the end of ...this.state.data with the value from the input | |
* then setState passing the new arra 'data' and re set inputText to empty. | |
* JSX displays the name and the vale of the event target. | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment