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 registration = { | |
username: "username", | |
password: "password", | |
isRegistering: false, | |
onRegister: r => { | |
r.isRegistering = true | |
setTimeout(() => { | |
r.isRegistering = false | |
}, 2000) |
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
componentWillMount() { | |
let proxy = {} | |
for (var i in this.state) { | |
if (typeof this.state[i] === "function") { | |
this.foos[i] = state[i].bind(null, proxy) | |
} else { | |
let key = i | |
Object.defineProperty(proxy, key, { | |
set: value => this.setState({ [key]: value }), |
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 registration = { | |
// ommitted for brevity | |
setUsername: (r, e) => { | |
let value = e.target.value | |
value = value.replace("-", "") | |
r.username = value | |
} | |
} |
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
const hoc = Wrapped => | |
class extends React.Component { | |
render() { | |
// pass props from parent to the wrapped component | |
return <Wrapped {...this.props} /> | |
} | |
} | |
// usage: | |
const WrappedComponent = hoc(SomeComponent) |
OlderNewer