Skip to content

Instantly share code, notes, and snippets.

@olegkalyta
Last active December 16, 2017 15:39
Show Gist options
  • Save olegkalyta/6cac0e538dcd00dc102539fd1d7d484f to your computer and use it in GitHub Desktop.
Save olegkalyta/6cac0e538dcd00dc102539fd1d7d484f to your computer and use it in GitHub Desktop.
class LoadableContainer extends Component {
componentDidMount() {
const { fetchData, data } = this.props
if (!data) {
fetchData()
}
}
render() {
const { children, isFetching, error, fetchData, ...rest } = this.props
if (isFetching) {
return <img src="spinner.gif" />
}
if (error) {
return <div>{error}</div>
}
const chidlrenWithProps = cloneElement(children, {...rest})
return (<div>{chidlrenWithProps}</div>)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment