Created
August 9, 2018 20:10
-
-
Save stephenjwatkins/7bd615ba64fd74c2018a7a6e024e44c5 to your computer and use it in GitHub Desktop.
Generic State component for React.
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"; | |
| import isFunction from "lodash/isFunction"; | |
| class State extends React.Component { | |
| constructor(...args) { | |
| super(...args); | |
| this.boundSetState = this.setState.bind(this); | |
| this.state = isFunction(this.props.initialState) | |
| ? { ...this.props.initialState(this.boundSetState) } | |
| : { ...this.props.initialState }; | |
| } | |
| render() { | |
| return this.props.children(this.state, this.boundSetState); | |
| } | |
| } | |
| export { State }; |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Probably best to use
react-powerpluginstead.