Skip to content

Commit 7fee38c

Browse files
committed
fix: children and props wrapper dependecies
1 parent d6b09c5 commit 7fee38c

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

package-lock.json

Lines changed: 23 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@
6363
"react-router-dom": "6.15.0",
6464
"redux": "4.2.0",
6565
"regenerator-runtime": "0.13.11",
66-
"tinymce": "5.10.7"
66+
"tinymce": "5.10.7",
67+
"use-deep-compare-effect": "^1.8.1"
6768
},
6869
"devDependencies": {
6970
"@edx/browserslist-config": "^1.2.0",

src/components/PluggableComponent/index.jsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import React, { useState, useEffect } from 'react';
33
import loadable from '@loadable/component';
44
import PropTypes from 'prop-types';
5+
import useDeepCompareEffect from 'use-deep-compare-effect';
56

67
import { isPluginAvailable } from './utils';
78

@@ -21,7 +22,7 @@ const PluggableComponent = ({
2122
id,
2223
...pluggableComponentProps
2324
}) => {
24-
const [newComponent, setNewComponent] = useState(children);
25+
const [newComponent, setNewComponent] = useState(children || null);
2526

2627
useEffect(() => {
2728
const loadPluginComponent = async () => {
@@ -47,7 +48,21 @@ const PluggableComponent = ({
4748
};
4849

4950
loadPluginComponent();
50-
}, [id, as, children]);
51+
}, [id, as]);
52+
53+
useEffect(() => {
54+
if (newComponent && children) {
55+
const updatedComponent = React.cloneElement(newComponent, pluggableComponentProps, children);
56+
setNewComponent(updatedComponent);
57+
}
58+
}, [children]);
59+
60+
useDeepCompareEffect(() => {
61+
if (newComponent) {
62+
const updatedComponent = React.cloneElement(newComponent, pluggableComponentProps, children);
63+
setNewComponent(updatedComponent);
64+
}
65+
}, [pluggableComponentProps]);
5166

5267
return newComponent;
5368
};

0 commit comments

Comments
 (0)