Skip to content

Commit 3ff3138

Browse files
author
Hrithik-Gavankar
committed
fix(NGUI-176): add error handling for missing components in DynamicComponent
1 parent 65dc963 commit 3ff3138

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/components/DynamicComponents.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ import { cloneElement, isValidElement, useState } from "react";
77

88
import { componentsMap } from "../constants/componentsMap";
99

10-
const FragmentWrapper = ({ children }: { children?: React.ReactNode }) => (
11-
<>{children}</>
12-
);
1310

1411
interface IProps {
1512
config: any;
@@ -87,7 +84,14 @@ const DynamicComponent = ({ config, customProps = {} }: IProps) => {
8784
return newProps;
8885
};
8986

90-
const Component = componentsMap[config?.component] || FragmentWrapper;
87+
// Check if component exists in componentsMap
88+
const Component = componentsMap[config?.component];
89+
90+
if (!Component) {
91+
// Throw an error for missing components so ErrorBoundary can catch it
92+
throw new Error(`Component "${config?.component}" is not available in the React package. Available components: ${Object.keys(componentsMap).join(', ')}`);
93+
}
94+
9195
const newProps = parseProps(config?.props || config);
9296

9397
return (

0 commit comments

Comments
 (0)