UNPKG

@zohodesk/utils

Version:

Unified Component Library - Utils

29 lines (24 loc) 511 B
import React from 'react'; export default class ErrorBoundary extends React.Component { constructor(props) { super(props); this.state = { hasError: false }; } static getDerivedStateFromError(error) { return { hasError: true, error }; } componentDidCatch(error, errorInfo) { console.log(error, errorInfo); } render() { if (this.state.hasError) { return this.props.renderFallback(this.state.error); } return this.props.children; } }