Last active
September 13, 2018 03:43
-
-
Save thulioph/c6beb96b24b87bb3a76772626566fa09 to your computer and use it in GitHub Desktop.
An example to demonstrate the withState API of Recompose
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 { 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