Skip to content

Commit 10a6d97

Browse files
committed
Refactor ExternalWrapper props
1 parent 0daf684 commit 10a6d97

File tree

2 files changed

+27
-28
lines changed

2 files changed

+27
-28
lines changed

@plotly/dash-test-components/src/components/ExternalComponent.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,23 @@ const ExternalComponent = ({ id, text, input_id, extra_component }) => {
88

99
return (
1010
<div id={id}>
11-
<ExternalWrapper
12-
id={input_id}
13-
componentType="Input"
14-
componentNamespace="dash_core_components"
15-
value={text}
11+
{text && <ExternalWrapper
12+
13+
component={{
14+
type: "Input",
15+
namespace: "dash_core_components",
16+
props: {
17+
value: text,
18+
id: input_id
19+
}
20+
}}
1621
componentPath={[...ctx.componentPath, 'external']}
17-
/>
22+
/>}
1823
{
1924
extra_component &&
2025
<ExternalWrapper
21-
componentType={extra_component.type}
22-
componentNamespace={extra_component.namespace}
26+
component={extra_component}
2327
componentPath={[...ctx.componentPath, 'extra']}
24-
{...extra_component.props}
2528
/>}
2629
</div>
2730
)

dash/dash-renderer/src/wrapper/ExternalWrapper.tsx

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, {useState, useEffect} from 'react';
22
import {batch, useDispatch} from 'react-redux';
33

4-
import {DashLayoutPath} from '../types/component';
4+
import {DashComponent, DashLayoutPath} from '../types/component';
55
import DashWrapper from './DashWrapper';
66
import {
77
addComponentToLayout,
@@ -11,21 +11,14 @@ import {
1111
} from '../actions';
1212

1313
type Props = {
14+
component: DashComponent;
1415
componentPath: DashLayoutPath;
15-
componentType: string;
16-
componentNamespace: string;
17-
[k: string]: any;
1816
};
1917

2018
/**
2119
* For rendering components that are out of the regular layout tree.
2220
*/
23-
function ExternalWrapper({
24-
componentType,
25-
componentNamespace,
26-
componentPath,
27-
...props
28-
}: Props) {
21+
function ExternalWrapper({component, componentPath}: Props) {
2922
const dispatch: any = useDispatch();
3023
const [inserted, setInserted] = useState(false);
3124

@@ -34,11 +27,7 @@ function ExternalWrapper({
3427
// The props will come from the parent so they can be updated.
3528
dispatch(
3629
addComponentToLayout({
37-
component: {
38-
type: componentType,
39-
namespace: componentNamespace,
40-
props: props
41-
},
30+
component,
4231
componentPath
4332
})
4433
);
@@ -50,12 +39,19 @@ function ExternalWrapper({
5039

5140
useEffect(() => {
5241
batch(() => {
53-
dispatch(updateProps({itempath: componentPath, props}));
54-
if (props.id) {
55-
dispatch(notifyObservers({id: props.id, props}));
42+
dispatch(
43+
updateProps({itempath: componentPath, props: component.props})
44+
);
45+
if (component.props.id) {
46+
dispatch(
47+
notifyObservers({
48+
id: component.props.id,
49+
props: component.props
50+
})
51+
);
5652
}
5753
});
58-
}, [props]);
54+
}, [component.props]);
5955

6056
if (!inserted) {
6157
return null;

0 commit comments

Comments
 (0)