Last active
March 11, 2016 11:29
-
-
Save martinandert/f03a224b37a3134947ee to your computer and use it in GitHub Desktop.
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
"use strict"; | |
var ControlledInput = (function() { | |
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | |
return React.createClass({ | |
displayName: "ControlledInput", | |
getInitialState: function getInitialState() { | |
return { value: this.props.value }; | |
}, | |
componentWillReceiveProps: function componentWillReceiveProps(nextProps) { | |
this.setState({ value: nextProps.value }); | |
}, | |
handleChange: function handleChange(e) { | |
this.setState({ value: e.target.value }); | |
this.props.onChange(e.target.value); | |
}, | |
render: function render() { | |
return React.createElement("input", _extends({ | |
type: "text" | |
}, this.props, { | |
value: this.state.value, | |
onChange: this.handleChange | |
})); | |
} | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment