Forked from sagiavinash/SimpleTextInput_CWRP.js
Last active
September 12, 2018 15:17
-
-
Save imbhargav5/1462854dbd43a745f21b6e682c5828a9 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 { | |
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