Created
June 7, 2018 03:29
-
-
Save JonathonAshworth/2c01c6b25c3c6ffd7660b649325644b4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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> | |
| ) | |
| } | |
| } |
This file contains hidden or 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
| 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