Skip to content

Instantly share code, notes, and snippets.

@fmoliveira
Forked from sibelius/ErrorBoundaryWithRetry.tsx
Created September 20, 2019 13:05
Show Gist options
  • Save fmoliveira/fc16b5ea51813b2c39907ca773cc12cf to your computer and use it in GitHub Desktop.
Save fmoliveira/fc16b5ea51813b2c39907ca773cc12cf 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