diff --git a/components/component-renderer/component-renderer.tsx b/components/component-renderer/component-renderer.tsx index 93f6f3e..c9dccc3 100644 --- a/components/component-renderer/component-renderer.tsx +++ b/components/component-renderer/component-renderer.tsx @@ -12,6 +12,7 @@ import { componentMap } from './mappings'; import { ComponentProps } from 'react'; +import ErrorBoundary from '#/components/error-boundary/error-boundary'; type ComponentMapType = typeof componentMap; type Data = ComponentProps['data']; @@ -41,7 +42,11 @@ export default function ComponentRenderer; + return ( + + + + ); } // If we don't know the component, we don't render anything diff --git a/components/error-boundary/error-boundary.tsx b/components/error-boundary/error-boundary.tsx new file mode 100644 index 0000000..cc1788c --- /dev/null +++ b/components/error-boundary/error-boundary.tsx @@ -0,0 +1,41 @@ +'use client'; + +import React, { ReactNode } from 'react'; + +interface Props { + children: ReactNode; +} + +interface ErrorBoundaryState { + errorMessage: string; +} +class ErrorBoundary extends React.Component { + constructor(props: Props) { + super(props); + } + + public state: ErrorBoundaryState = { + errorMessage: '', + }; + + static getDerivedStateFromError(error: Error): ErrorBoundaryState { + return { errorMessage: error.message }; + } + + render() { + if (this.state.errorMessage) { + return ( +
+
+ Unable to render the component. +
{this.state.errorMessage}
+
+
+ ); + } + + return this.props.children; + } +} + +export default ErrorBoundary;