Skip to content

Instantly share code, notes, and snippets.

@thulioph
Last active September 13, 2018 03:52
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/98cffaf64bff4853fec6e86af6fff4df to your computer and use it in GitHub Desktop.
Save thulioph/98cffaf64bff4853fec6e86af6fff4df to your computer and use it in GitHub Desktop.
An example to demonstrate the branch API of Recompose
import React from 'react';
import { branch } from 'recompose';
const MyComponent = () => <h2>Hello!</h2>;
const IsLessThanZero = BaseComponent => props => (
<div>
<BaseComponent {...props} />
<h1>Less or equal than zero!</h1>
</div>
);
const IsMoreThanZero = BaseComponent => props => (
<div>
<BaseComponent {...props} />
<h1>More than zero!</h1>
</div>
);
const MyComponentModified = branch(
(props) => (props.value > 0 ? true : false),
IsMoreThanZero,
IsLessThanZero
)(MyComponent);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment