Skip to content

Instantly share code, notes, and snippets.

@wsrast
Last active December 18, 2018 19:10
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 wsrast/6e8d26242b906ab767d1b448409b798f to your computer and use it in GitHub Desktop.
Save wsrast/6e8d26242b906ab767d1b448409b798f to your computer and use it in GitHub Desktop.
A base HOC pattern
import React from "react";
import { withHandlers, withState, compose } from "recompose";
const RenderComponent = ({ handleClick, stateValue, newValue }) => {
return (
<button onClick={handleClick}>
RenderComponent ({stateValue.value} clicks!)
</button>
);
};
const enhance = compose(
withState("stateValue", "setStateValue", { value: 0 }),
withHandlers({
handleClick: props => val => {
props.setStateValue(({ value }) => ({ value: value + 1 }));
}
})
);
export default enhance(RenderComponent);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment