Last active
September 26, 2017 14:46
-
-
Save tpetrina/52c44636a426f64f9b15b5819af8c4f0 to your computer and use it in GitHub Desktop.
React form complication 4
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
export const wrap = (state, WrappedComponent) => | |
class extends React.Component { | |
foos = {} | |
state = state || {} | |
set = e => { | |
this.setState({ [e.target.name]: e.target.value }) | |
}; | |
componentWillMount() { | |
for (var i in this.state) { | |
if (typeof this.state[i] === "function") | |
this.foos[i] = state[i].bind(null, this) | |
} | |
} | |
render() { | |
return ( | |
<WrappedComponent {...this.props} {...this.state} {...this.foos} set={this.set} /> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment