Skip to content

Instantly share code, notes, and snippets.

@quisido
Created November 1, 2018 00:22
Show Gist options
  • Save quisido/edd47e2d8d25fa716a7f8085ba767c60 to your computer and use it in GitHub Desktop.
Save quisido/edd47e2d8d25fa716a7f8085ba767c60 to your computer and use it in GitHub Desktop.
React Suspense with the Fetch API
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