Skip to content

Commit

Permalink
chore(www): add ErrorBoundary in API Reference components
Browse files Browse the repository at this point in the history
  • Loading branch information
matuzalemsteles committed Jan 13, 2025
1 parent 81e655d commit 1a27757
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/clay-drop-down/docs/drop-down.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ packageNpm: '@clayui/drop-down'
packageUse: "import DropDown from '@clayui/drop-down';"
packageTypes:
[
'clay-drop-down/src/DropDown.tsx',
'clay-drop-down/src/Action.tsx',
'clay-drop-down/src/Item.tsx',
'clay-drop-down/src/ItemList.tsx',
Expand Down
20 changes: 17 additions & 3 deletions www/app/_components/APIReference.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import type {JavaScriptFileExport} from 'renoun/file-system';
import {CodeInline, MDXRenderer, MDXComponents} from 'renoun/components';
import {ComponentsCollection} from '@/data';

import {ErrorBoundary} from './ErrorBoundary';

const mdxComponents = {
p: (props) => <p {...props} style={{margin: 0}} />,
code: (props) => <MDXComponents.code {...props} paddingY="0" />,
Expand Down Expand Up @@ -35,10 +37,22 @@ export type APIReferenceProps =

/** Displays type documentation for all types exported from a file path or types related to a collection export source. */
export function APIReference(props: APIReferenceProps) {
const path = (props.source as string).split('/');

return (
<Suspense fallback="Loading API references...">
<APIReferenceAsync {...props} />
</Suspense>
<ErrorBoundary
fallback={
<div className="alert alert-danger">
<strong className="lead">Error:</strong> An error occurred
while generating the Table API for the{' '}
{path[path.length - 1]} component.
</div>
}
>
<Suspense fallback="Loading API references...">
<APIReferenceAsync {...props} />
</Suspense>
</ErrorBoundary>
);
}

Expand Down
31 changes: 31 additions & 0 deletions www/app/_components/ErrorBoundary.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use client';

import React from 'react';

type Props = {
fallback: React.ReactNode;
children: React.ReactNode;
};

export class ErrorBoundary extends React.Component<Props, any> {
constructor(props: any) {
super(props);
this.state = {hasError: false};
}

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

componentDidCatch(error: any, info: any) {
console.log(error, info);
}

render() {
if (this.state.hasError) {
return this.props.fallback;
}

return this.props.children;
}
}

0 comments on commit 1a27757

Please sign in to comment.