Created
August 2, 2015 22:57
-
-
Save jsdf/40ed3e745fcc3b2f8fbb to your computer and use it in GitHub Desktop.
Private state in React Components
This file contains hidden or 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
let UsernameField = (() => { | |
const _username = Symbol(); | |
const _handleNameChange = Symbol(); | |
return class UsernameField extends React.Component { | |
state = { | |
[_username]: 'DefaultUser', | |
} | |
[_handleNameChange] = (e) => { | |
this.setState({ | |
[_username]: e.target.value, | |
}); | |
} | |
render() { | |
return ( | |
<input | |
value={this.state[_username]} | |
onChange={this[_handleNameChange]} | |
/> | |
); | |
} | |
} | |
})(); |
This file contains hidden or 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
// UsernameField.js babel-transpiled, uglified then beautified | |
"use strict"; | |
var UsernameField = function() { | |
var e = Symbol(), t = Symbol(); | |
return function(r) { | |
function n() { | |
var r = this; | |
_classCallCheck(this, n), _get(Object.getPrototypeOf(n.prototype), "constructor", this).apply(this, arguments), | |
this.state = _defineProperty({}, e, "DefaultUser")[t] = function(t) { | |
r.setState(_defineProperty({}, e, t.target.value)); | |
}; | |
} | |
return _inherits(n, r), _createClass(n, [ { | |
key: "render", | |
value: function() { | |
return React.createElement("input", { | |
value: this.state[e], | |
onChange: this[t] | |
}); | |
} | |
} ]), n; | |
}(React.Component); | |
}(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment