Skip to content

Commit

Permalink
feat: allow to render NMRium without error boundary (#2489)
Browse files Browse the repository at this point in the history
This way we can wrap it with a different error boundary.
  • Loading branch information
targos committed Jun 30, 2023
1 parent e677e06 commit 8bde9b9
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/component/NMRium.tsx
Expand Up @@ -127,6 +127,7 @@ export type OnNMRiumChange = (
export interface NMRiumProps {
data?: NMRiumData;
onChange?: OnNMRiumChange;
noErrorBoundary?: boolean;
onError?: ErrorBoundaryPropsWithComponent['onError'];
workspace?: NMRiumWorkspace;
customWorkspaces?: CustomWorkspaces;
Expand Down Expand Up @@ -163,14 +164,19 @@ const NMRium = forwardRef<NMRiumRef, NMRiumProps>(function NMRium(
props: NMRiumProps,
ref,
) {
const { onError, ...otherProps } = props;
return (
<RootLayout style={{ width: '100%' }}>
<ErrorBoundary FallbackComponent={ErrorOverlay} onError={onError}>
<InnerNMRium {...otherProps} innerRef={ref} />
</ErrorBoundary>
</RootLayout>
const { noErrorBoundary = false, onError, ...otherProps } = props;

const innerNmrium = <InnerNMRium {...otherProps} innerRef={ref} />;

const children = noErrorBoundary ? (
innerNmrium
) : (
<ErrorBoundary FallbackComponent={ErrorOverlay} onError={onError}>
{innerNmrium}
</ErrorBoundary>
);

return <RootLayout style={{ width: '100%' }}>{children}</RootLayout>;
});

type InnerNMRiumProps = Omit<NMRiumProps, 'onError'> & {
Expand Down

0 comments on commit 8bde9b9

Please sign in to comment.