Created
February 8, 2018 22:36
-
-
Save bob-lee/53f9bae30259ef078dd1e2ac16892ab3 to your computer and use it in GitHub Desktop.
This file contains 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
// Work.js | |
import withObserver from './withObserver' | |
import Images from './Images' | |
const ImagesWithObserver = withObserver(Images) | |
export default ImagesWithObserver | |
// withObserver.js (HOC composing Observer and wrapped components) | |
import React from 'react'; | |
import Observer from './Observer' | |
export default function withObserver(WrappedComponent) { | |
return class extends Observer { | |
render() { | |
return ( | |
<WrappedComponent | |
list={this.state.list} | |
onImageLoaded={this.observe} | |
{...this.props} /> | |
) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment