Rev 1198 | Rev 1200 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
import React from 'react'import { connect } from 'react-redux'import { addNotification } from '../../redux/notification/notification.actions'import { Container } from '@mui/material'import { ButtonPrimary } from '@buttons'import { Title } from 'components/micro-learning/Typography'class ErrorBoundary extends React.Component {constructor(props) {super(props)this.state = { hasError: false }}componentDidCatch(error, errorInfo) {this.setState({ hasError: true })console.error('ErrorBoundary caught an error: ', error, errorInfo)this.props.addNotification({ style: 'danger', msg: error.message })}render() {if (this.state.hasError) {return (<Container><Title>Something went wrong, please reload the page</Title><ButtonPrimaryclassName='mt-3'onClick={() => window.location.reload()}label='Reload'/></Container>)}return this.props.children}}const mapDispatchToProps = {addNotification: (notification) => addNotification(notification)}export default connect(null, mapDispatchToProps)(ErrorBoundary)