Created
September 19, 2019 22:19
-
-
Save sibelius/fe79d5e067dcfdaef45cb63985bdd520 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