Skip to content

Instantly share code, notes, and snippets.

@imbhargav5
Forked from sagiavinash/SimpleTextInput_CWRP.js
Last active September 12, 2018 15:17
Show Gist options
  • Save imbhargav5/1462854dbd43a745f21b6e682c5828a9 to your computer and use it in GitHub Desktop.
Save imbhargav5/1462854dbd43a745f21b6e682c5828a9 to your computer and use it in GitHub Desktop.
SimpleTextInput with CWRP
class SimpleTextInput extend Component {
constructor(props){
super(props)
this.state = {
value : props.value,
_value : props.value
}
}
static getDerivedStateFromProps(newProps,oldState){
if(newProps.value !== oldState._value){
return {
_value : newProps.value,
value : newProps.value
}
}else{
return null
}
}
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