Last active
December 18, 2018 19:10
-
-
Save wsrast/6e8d26242b906ab767d1b448409b798f to your computer and use it in GitHub Desktop.
A base HOC pattern
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 { 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