Skip to content

Instantly share code, notes, and snippets.

@martinandert
Last active March 11, 2016 11:29
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save martinandert/f03a224b37a3134947ee to your computer and use it in GitHub Desktop.
"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