Skip to content

Instantly share code, notes, and snippets.

@sagiavinash
Created September 12, 2018 13:31
Show Gist options
  • Save sagiavinash/cb682afb57add9b426826d0423023d73 to your computer and use it in GitHub Desktop.
Save sagiavinash/cb682afb57add9b426826d0423023d73 to your computer and use it in GitHub Desktop.
SimpleTextInput with CWRP
class SimpleTextInput extend Component {
state = {
value: this.props.value,
};
componentWillReceiveProps(nextProps) {
if (this.props.value !== nextProps.value) {
this.setState({value: nextProps.value});
}
}
render() {
return (
<input
value={this.state.value}
onKeyPress={(e) => {
if (e.keyCode === 13) {
this.props.onChange(this.state.value);
}
}}
onChange={(e)=> this.setState({value: e.target.value})
/>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment