Created
September 13, 2018 04:29
-
-
Save thulioph/a89b2d7f20748910be77365365549595 to your computer and use it in GitHub Desktop.
An example to demonstrate the mapProps 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 { compose, withState, mapProps } from 'recompose'; | |
const MyComponent = ({ myCounter, setCounter }) => ( | |
<div> | |
<h1>{myCounter}</h1> | |
<button onClick={() => setCounter(myCounter + 1)}>Add</button> | |
<button onClick={() => setCounter(myCounter - 1)}>Remove</button> | |
</div> | |
); | |
const MyComponentWithState = compose( | |
withState("counter", "setCounter", 0), | |
mapProps(({ counter, ...rest }) => { | |
return { | |
myCounter: counter, | |
...rest | |
}; | |
}) | |
)(MyComponent); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment