Skip to content

Instantly share code, notes, and snippets.

@w33ble
Created May 16, 2017 20:52
Show Gist options
  • Save w33ble/3efc1f9005bf20dbe0d5a63015dea8e8 to your computer and use it in GitHub Desktop.
Save w33ble/3efc1f9005bf20dbe0d5a63015dea8e8 to your computer and use it in GitHub Desktop.
recompose example
import { renderComponent, branch, compose } from 'recompose';
import { MyComponent as Component } from './my_expression';
import { Loading } from '../loading';
const renderLoading = branch(
props => Boolean(props.loading), // bool, test for loading state
renderComponent(Loading)
);
const addProps = withProps((ownProps) => {
// TODO: create some new props, maybe using ownProps
return {
date: new Date()
};
});
// component gets a `date` property
// and if props.loading === true, it'll render the Loading component instead
export const MyComponent = compose(
addProps,
renderLoading
)(Component);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment