Skip to content

Commit

Permalink
fix: [ComponentsProvider] support updating props.components
Browse files Browse the repository at this point in the history
  • Loading branch information
akai committed Mar 9, 2021
1 parent d933955 commit 524401d
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/components/ComponentsProvider/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useEffect } from 'react';
import { lazyComponent } from '../../utils/lazyComponent';
import { LazyComponentWithCode } from '../LazyComponent';
import { ComponentsContext } from './ComponentsContext';
Expand All @@ -14,7 +14,14 @@ export type { ComponentsProviderProps, ComponentsMap };

export const ComponentsProvider: React.FC<ComponentsProviderProps> = (props) => {
const { components, children } = props;
const componentsRef = React.useRef(components || {});
const componentsRef = React.useRef<ComponentsMap>({ ...components });

useEffect(() => {
componentsRef.current = {
...components,
...componentsRef.current,
};
}, [components]);

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

0 comments on commit 524401d

Please sign in to comment.