Skip to content

Instantly share code, notes, and snippets.

@thulioph
Created September 13, 2018 04:29
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/a89b2d7f20748910be77365365549595 to your computer and use it in GitHub Desktop.
Save thulioph/a89b2d7f20748910be77365365549595 to your computer and use it in GitHub Desktop.
An example to demonstrate the mapProps API of Recompose
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