Skip to content

Instantly share code, notes, and snippets.

@niradler
Last active November 20, 2017 17:04
Show Gist options
  • Save niradler/5ea503fc409caa479a6d75c03b6e517e to your computer and use it in GitHub Desktop.
Save niradler/5ea503fc409caa479a6d75c03b6e517e to your computer and use it in GitHub Desktop.
react input component
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