Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
refactor: add AppErrorBounday component
Browse files Browse the repository at this point in the history
  • Loading branch information
korhaliv committed Aug 14, 2019
1 parent 21ab955 commit 3b342c1
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions renderer/components/App/AppErrorBoundary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { mainLog } from '@zap/utils/log'
import AppCrashedDialog from 'components/Dialog/AppCrashed'

export default class AppErrorBoundary extends Component {
static propTypes = {
children: PropTypes.node,
}

constructor(props) {
super(props)
this.state = { error: null }
}

static getDerivedStateFromError(error) {
mainLog.error(error)
return { error }
}

render() {
const { error } = this.state
const { children } = this.props
if (error) {
return <AppCrashedDialog error={error} isOpen />
}

return children
}
}

0 comments on commit 3b342c1

Please sign in to comment.