Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 2206 | Rev 2284 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1197 stevensc 1
import React from 'react'
2
import { connect } from 'react-redux'
1202 stevensc 3
 
1565 stevensc 4
import { addNotification } from '@app/redux/notification/notification.actions'
1197 stevensc 5
 
6
class ErrorBoundary extends React.Component {
2209 stevensc 7
  constructor(props) {
8
    super(props)
9
    this.state = { hasError: false }
10
  }
11
 
12
  static getDerivedStateFromError() {
13
    return { hasError: true }
14
  }
15
 
2205 stevensc 16
  componentDidCatch(error, errorInfo) {
2209 stevensc 17
    console.error('ErrorBoundary caught an error: ', error, errorInfo)
18
    this.props.addNotification({ style: 'danger', msg: error.message })
1606 stevensc 19
  }
20
 
1197 stevensc 21
  render() {
22
    return this.props.children
23
  }
24
}
25
 
2209 stevensc 26
const mapDispatchToProps = {
27
  addNotification: (notification) => addNotification(notification)
28
}
29
 
30
export default connect(null, mapDispatchToProps)(ErrorBoundary)