Last active
November 20, 2017 17:04
-
-
Save niradler/5ea503fc409caa479a6d75c03b6e517e to your computer and use it in GitHub Desktop.
react input component
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
import React, {Component} from 'react'; | |
class Input extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
value: '' | |
}; | |
this.handleChange = this | |
.handleChange | |
.bind(this); | |
this.handleBlur = this | |
.handleBlur | |
.bind(this); | |
} | |
handleChange(e) { | |
this.setState({value: e.target.value}); | |
if (typeof(this.props.onChange) === 'function') | |
this.props.onChange(e) | |
} | |
handleBlur(e) { | |
if (typeof(this.props.onBlur) === 'function') | |
this.props.onBlur(e); | |
} | |
render() { | |
return (React.createElement('input', { | |
...this.props, | |
onChange: this.handleChange, | |
onBlur: this.handleBlur | |
}, null)); | |
} | |
} | |
export default Input; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment