Skip to content

Instantly share code, notes, and snippets.

Created March 11, 2018 11:13
Show Gist options
  • Save anonymous/56dcae530e1a85fbef73f06f72c92de7 to your computer and use it in GitHub Desktop.
Save anonymous/56dcae530e1a85fbef73f06f72c92de7 to your computer and use it in GitHub Desktop.
const { withStateHandlers } = Recompose;
const Counter = ({ count, increment, decrement }) =>
<div>
Count: {count}
<div>
<button onClick={increment}>+</button>
<button onClick={decrement}>-</button>
</div>
</div>;
const App = withStateHandlers(
{
count: 0
},
{
increment: ({ count }) => () => ({ count: count + 1 }),
decrement: ({ count }) => () => ({ count: count - 1 })
}
)(Counter);
ReactDOM.render(<App />, document.getElementById("container"));
<div id="container">
<!-- This element's contents will be replaced with your component. -->
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment