Skip to content

Instantly share code, notes, and snippets.

@thulioph
Created Sep 13, 2018
Embed
What would you like to do?
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