Created
September 12, 2018 13:31
-
-
Save sagiavinash/cb682afb57add9b426826d0423023d73 to your computer and use it in GitHub Desktop.
SimpleTextInput with CWRP
This file contains 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
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