Skip to content

Instantly share code, notes, and snippets.

@ryanflorence
Created February 11, 2016 17:12
Show Gist options
  • Save ryanflorence/4e79ea80073db4051c9a to your computer and use it in GitHub Desktop.
Save ryanflorence/4e79ea80073db4051c9a to your computer and use it in GitHub Desktop.
import serializeForm from 'form-serialize'
const Something = React.createClass({
getInitialState() {
return {
form: {}
}
},
syncFormToState(event) {
this.setState({
form: serializeForm(event.target, { hash: true })
})
},
render() {
return (
<form onChange={this.syncFormToState}>
<input name="one"/>
<input name="two"/>
<input name="three[four]"/>
<input name="three[five]"/>
</form>
)
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment