-
-
Save fmoliveira/fc16b5ea51813b2c39907ca773cc12cf to your computer and use it in GitHub Desktop.
ErrorBoundaryWithRetry to be used with relay useQuery hook
This file contains 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 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