Skip to content

Instantly share code, notes, and snippets.

@samcorcos
Created February 24, 2017 01:01
Show Gist options
  • Save samcorcos/ecf65ae1f88f423ee26e5f414ed1101a to your computer and use it in GitHub Desktop.
Save samcorcos/ecf65ae1f88f423ee26e5f414ed1101a to your computer and use it in GitHub Desktop.
Locally controlled react form
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