Skip to content

Instantly share code, notes, and snippets.

@thulioph
Last active September 13, 2018 03:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thulioph/c6beb96b24b87bb3a76772626566fa09 to your computer and use it in GitHub Desktop.
Save thulioph/c6beb96b24b87bb3a76772626566fa09 to your computer and use it in GitHub Desktop.
An example to demonstrate the withState API of Recompose
import React from 'react';
import { withState } from 'recompose';
const MyComponent = ({ counter, setCounter }) => (
<div>
<h1>{counter}</h1>
<button onClick={() => setCounter(counter + 1)}>Add</button>
<button onClick={() => setCounter(counter - 1)}>Remove</button>
</div>
);
const MyComponentWithState = withState('counter', 'setCounter', 0)(MyComponent);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment