Created
November 1, 2018 00:22
-
-
Save quisido/edd47e2d8d25fa716a7f8085ba767c60 to your computer and use it in GitHub Desktop.
React Suspense with the Fetch API
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 Suspense extends React.Component { | |
| constructor(props) { | |
| super(props); | |
| this.state = { | |
| error: null | |
| }; | |
| } | |
| componentDidCatch(e) { | |
| this.setState({ error: e }); | |
| } | |
| render() { | |
| if (this.state.error) { | |
| return this.props.fallback; | |
| } | |
| return this.props.children; | |
| } | |
| } | |
| /* | |
| <Suspense fallback={<Loading />}> | |
| <ErrorThrower /> | |
| </Suspense> | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment