Created
May 16, 2017 20:52
-
-
Save w33ble/3efc1f9005bf20dbe0d5a63015dea8e8 to your computer and use it in GitHub Desktop.
recompose example
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 { 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