Skip to content

Instantly share code, notes, and snippets.

@asimonok
Created January 13, 2021 17:28
Show Gist options
  • Save asimonok/b0b33d7e0d581c279fea9119decfe31d to your computer and use it in GitHub Desktop.
Save asimonok/b0b33d7e0d581c279fea9119decfe31d to your computer and use it in GitHub Desktop.
const withLoadingListData = (BaseComponent) =>
class WithLoadingListData extends Component {
state = {
list: [],
isLoading: true,
}
componentDidMount () {
setTimeout(() => {
this.setState({
list: ['Apple', 'Orange', 'Pineapple'],
isLoading: false,
})
}, 2000)
}
render () {
return this.state.isLoading
? 'Loading...'
: <BaseComponent list={this.state.list} />
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment