Last active
January 28, 2017 02:17
-
-
Save johntran/fdb87f0e81c8d70a01c9f360ba392fec to your computer and use it in GitHub Desktop.
Higher-Order Functions: Loading Indicator
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
// Working with loading indicators | |
// before | |
class PersonRenderer extends Component { | |
render() { | |
if (this.props.person) { | |
return (<div>personcontent</div>) | |
} | |
return <LoadingIndicator/> | |
} | |
} | |
//after | |
const withLoadingIndicator = Wrapped => ({loading, ...otherProps}) => | |
props.loading ? | |
<LoadingIndicator /> | |
: <Wrapped {...otherProps} /> | |
// ... | |
export class PersonRenderer extends Component { | |
render() { | |
return (<div>personcontent</div>) | |
} | |
} | |
export default withLoadingIndicator(PersonRenderer); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment