Skip to content

Commit 524401d

Browse files
committed
fix: [ComponentsProvider] support updating props.components
1 parent d933955 commit 524401d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/components/ComponentsProvider/index.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { useEffect } from 'react';
22
import { lazyComponent } from '../../utils/lazyComponent';
33
import { LazyComponentWithCode } from '../LazyComponent';
44
import { ComponentsContext } from './ComponentsContext';
@@ -14,7 +14,14 @@ export type { ComponentsProviderProps, ComponentsMap };
1414

1515
export const ComponentsProvider: React.FC<ComponentsProviderProps> = (props) => {
1616
const { components, children } = props;
17-
const componentsRef = React.useRef(components || {});
17+
const componentsRef = React.useRef<ComponentsMap>({ ...components });
18+
19+
useEffect(() => {
20+
componentsRef.current = {
21+
...components,
22+
...componentsRef.current,
23+
};
24+
}, [components]);
1825

1926
function addComponent(code: string, val: ComponentInterface) {
2027
componentsRef.current[code] = val;

0 commit comments

Comments
 (0)