Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3456 | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |

import React from 'react';
import { connect } from 'react-redux';

import { addNotification } from '@store/notification/notification.actions';

class ErrorBoundary extends React.Component {
  constructor(props) {
    super(props);
    this.state = { hasError: false };
  }

  static getDerivedStateFromError() {
    return { hasError: true };
  }

  componentDidCatch(error, errorInfo) {
    console.error('ErrorBoundary caught an error: ', error, errorInfo);
    this.props.addNotification({ style: 'danger', msg: 'Ha ocurrido un error inesperado' });
  }

  render() {
    return this.props.children;
  }
}

const mapDispatchToProps = {
  addNotification: (notification) => addNotification(notification)
};

export default connect(null, mapDispatchToProps)(ErrorBoundary);