Skip to content

Instantly share code, notes, and snippets.

@johntran
Last active January 28, 2017 02:17
Show Gist options
  • Save johntran/fdb87f0e81c8d70a01c9f360ba392fec to your computer and use it in GitHub Desktop.
Save johntran/fdb87f0e81c8d70a01c9f360ba392fec to your computer and use it in GitHub Desktop.
Higher-Order Functions: Loading Indicator
// 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