huridocs/uwazi

View on GitHub
app/react/V2/Components/ErrorHandling/RouteErrorBoundary.tsx

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
import React from 'react';
import { useRouteError } from 'react-router-dom';
import { ErrorFallback } from './ErrorFallback';

interface ErrorBoundaryProps {
  error?: Error;
  children?: React.ReactElement;
}

const RouteErrorBoundary = ({ error: elementError, children = <> </> }: ErrorBoundaryProps) => {
  const routeError = useRouteError() as Error;
  const error = elementError || routeError;
  if (error?.message) {
    return <ErrorFallback error={error} />;
  }
  return children;
};

export { RouteErrorBoundary };