Skip to content

Instantly share code, notes, and snippets.

@sibelius
Created September 19, 2019 22:19
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sibelius/fe79d5e067dcfdaef45cb63985bdd520 to your computer and use it in GitHub Desktop.
Save sibelius/fe79d5e067dcfdaef45cb63985bdd520 to your computer and use it in GitHub Desktop.
ErrorBoundaryWithRetry to be used with relay useQuery hook
class ErrorBoundaryWithRetry extends React.Component<Props, State> {
state = {error: null};
static getDerivedStateFromError(error): State {
return {error: error};
}
_retry = () => {
this.setState({error: null});
}
render() {
const {children, fallback} = this.props;
const {error} = this.state;
if (error) {
if (typeof fallback === 'function') {
return fallback(error, this._retry);
}
return fallback;
}
return children;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment