Created
February 24, 2017 01:01
-
-
Save samcorcos/ecf65ae1f88f423ee26e5f414ed1101a to your computer and use it in GitHub Desktop.
Locally controlled react form
This file contains hidden or 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
import React from 'react' | |
export class Form extends React.PureComponent { | |
constructor(props) { | |
super(props) | |
this.state = { | |
input1: null, | |
input2: null, | |
} | |
} | |
handleChange(e, key) { | |
this.setState({ [key]: e.target.value, }) | |
} | |
render() { | |
return ( | |
<div> | |
<input | |
onChange={e => this.handleChange(e, 'input1')} | |
type={'text'} /> | |
<input | |
onChange={e => this.handleChange(e, 'input2')} | |
type={'text'} /> | |
</div> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment