Skip to content

Instantly share code, notes, and snippets.

@darrylhebbes
Forked from anonymous/fiddle.babel + jsx
Created March 11, 2018 11:14
Show Gist options
  • Save darrylhebbes/5c5afb2f67ad90089efa3ba2344a563b to your computer and use it in GitHub Desktop.
Save darrylhebbes/5c5afb2f67ad90089efa3ba2344a563b 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