Skip to content

Instantly share code, notes, and snippets.

@komkanit
Last active January 29, 2017 03:13
Show Gist options
  • Select an option

  • Save komkanit/962c34cfda28e5bebe9124b76d303221 to your computer and use it in GitHub Desktop.

Select an option

Save komkanit/962c34cfda28e5bebe9124b76d303221 to your computer and use it in GitHub Desktop.
const CalculateWrapper = (WrappedComponent, operation) => (props) => (
<div>
<div>{props.x + operation + props.y}</div>
<WrappedComponent {...props} />
</div>
)
const Increment = (props) => ( <h1>{props.x + props.y}</h1> )
const Decrease = (props) => ( <h1>{props.x - props.y}</h1> )
class App extends Component {
render() {
const CalculateIncrement = CalculateWrapper(Increment, '+')
const CalculateDecrease = CalculateWrapper(Decrease, '-')
return (
<div className="App">
<CalculateIncrement x={10} y={20} />
<CalculateDecrease x={10} y={20} />
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment