Skip to content

Instantly share code, notes, and snippets.

@jquense
Created July 1, 2016 17:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jquense/867760097250515ce78325f515936baf to your computer and use it in GitHub Desktop.
Save jquense/867760097250515ce78325f515936baf to your computer and use it in GitHub Desktop.
class Form extends React.Component {
constructor() {
super()
this.state = {
name: null
}
}
componentWillReceiveProps(nextProps) {
if (nextProps.initialData && !this.props.initialData) {
this.setState(this.nextProps.initialData)
}
}
render() {
return (
<div>
<input
onChange={e => this.setState({ name: e.target.value })}
value={this.state.name}
/>
</div>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment