Skip to content

Instantly share code, notes, and snippets.

@tpetrina
Last active September 26, 2017 14:46
Show Gist options
  • Save tpetrina/52c44636a426f64f9b15b5819af8c4f0 to your computer and use it in GitHub Desktop.
Save tpetrina/52c44636a426f64f9b15b5819af8c4f0 to your computer and use it in GitHub Desktop.
React form complication 4
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