Skip to content

Instantly share code, notes, and snippets.

@JonathonAshworth
Created June 7, 2018 03:29
Show Gist options
  • Save JonathonAshworth/2c01c6b25c3c6ffd7660b649325644b4 to your computer and use it in GitHub Desktop.
Save JonathonAshworth/2c01c6b25c3c6ffd7660b649325644b4 to your computer and use it in GitHub Desktop.
class FooPage {
async loadData () {
const data = await getData()
this.setState({ data })
}
render () {
return (
<Page data={this.state.data} loadData={this.loadData}>
{data => (
<div>{data.foo.bar}</div>
)}
</Page>
)
}
}
class Page {
constructor () {
this.state = { loading: true }
}
componentDidMount () {
await this.props.loadData()
this.setState({ loading: false })
}
render () {
if (this.state.loading)
return <div>Loading!</div>
else
return this.props.children(data)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment