Created
September 6, 2017 02:34
-
-
Save fakenickels/7d0206817cc0903d4674f1dbf7efd5e6 to your computer and use it in GitHub Desktop.
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
import React from 'react' | |
export default (stateName, handlerName, defaultValue) => Component => | |
class StateHandler extends React.Component { | |
state = { [stateName]: defaultValue } | |
constructor(props) { | |
super(props) | |
this[handlerName] = (value) => this.setState({ [stateName]: value }) | |
} | |
render() { | |
const props = { [handlerName]: this[handlerName], ...this.props, ...this.state} | |
return <Component {...props} /> | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment