-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ErrorBoundary, in case that improves error-handling
- Loading branch information
1 parent
cbc3910
commit 3a46a26
Showing
2 changed files
with
41 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Component } from 'react' | ||
|
||
// Adapted from https://nextjs.org/docs/pages/building-your-application/configuring/error-handling | ||
class ErrorBoundary extends Component { | ||
constructor(props) { | ||
super(props) | ||
this.state = { hasError: false } | ||
} | ||
static getDerivedStateFromError(error) { | ||
return { hasError: true } | ||
} | ||
componentDidCatch(error, errorInfo) { | ||
console.log({ error, errorInfo }) | ||
} | ||
render() { | ||
if (!this.state.hasError) { | ||
return this.props.children | ||
} | ||
return ( | ||
<p> | ||
There was a glitch.{' '} | ||
<button | ||
type="button" | ||
onClick={() => this.setState({ hasError: false })} | ||
style={{ backgroundColor: '#7aefb3', padding: '0.5rem 0.75rem', marginInline: '0.5rem' }} | ||
> | ||
Try again? | ||
</button> | ||
</p> | ||
) | ||
} | ||
} | ||
|
||
export default ErrorBoundary |
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