Created
March 20, 2017 19:47
-
-
Save robrichard/fbd91bd246d2fbe5ae479651613881dc 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 MyForm extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
input: { | |
email: "", | |
name: "" | |
} | |
}; | |
} | |
handleInputChange(newPartialInput) { | |
this.setState(state => ({ | |
...state, | |
input: { | |
...state.input, | |
...newPartialInput | |
} | |
})) | |
} | |
render() { | |
const {input} = this.state; | |
return ( | |
<form onSubmit={() => /* save your form here */}> | |
<div> | |
<input | |
name="email" | |
placeholder="email" | |
value={input.email} | |
onChange={e => this.handleInputChange({email: e.target.value})} | |
/> | |
</div> | |
<div> | |
<input | |
name="name" | |
placeholder="name" | |
value={input.name} | |
onChange={e => this.handleInputChange({name: e.target.value})} | |
/> | |
</div> | |
<div> | |
<button type="submit">Submit</button> | |
</div> | |
</form> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment