Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix Error Boundary
  • Loading branch information
erikmajlath authored and dannytce committed Apr 24, 2019
commit a4b8ae706ca039b0fc70da300bdd8435134abeb7
24 changes: 19 additions & 5 deletions src/components/ErrorBoundary/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,29 @@ import React from 'react'
import { toast } from 'react-toastify'

export class ErrorBoundary extends React.Component {
componentDidCatch(error, info) {
toast.error(`Error: ${error.message}`, {
position: toast.POSITION.TOP_CENTER,
})
state = {
error: false,
}

static getDerivedStateFromError() {
return {
error: true,
}
}

componentDidCatch(error, info) {
toast.error(`Error: ${error.message}`)
console.error('Error boundary error', error, info)
}

render() {
return this.props.children
return this.state.error ? (
<h2>
We are sorry! There was an error which we were not able to recover from.
Please refresh the page
</h2>
) : (
this.props.children
)
}
}