Created
April 7, 2018 15:20
-
-
Save talves/8a59acd47bf3a62b17035fa04f370a5e to your computer and use it in GitHub Desktop.
Revisions
-
talves created this gist
Apr 7, 2018 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ import { Component } from 'react' export default class MicroState extends Component { constructor (props) { super(props) this.state = props.state } render () { return (this.props.render || this.props.children)({ setState: (...args) => this.setState(...args), ...this.state, }) } } // Usage // <MicroState // state={{ // count: 0 // }} // render={({ count, setState }) => ( // <div> // <div>Count: {count}</div> // <button // onClick={() => setState({count: count + 1})} // > // Increment Count // </button> // </div> // )} // />