Skip to content

Commit 8d65c82

Browse files
committed
lib: Make DynamicListForm.itemcomponent a component type instead of instance
Existing callers in podman/machines used it like that: <DynamicListForm ... itemcomponent={ <PublishPort />} /> But from a conceptual as well as type-check perspective this is nonsense: This is a totally invalid object as it does not get any (required) properties. It needlessly runs initialization, and can never actually get rendered. Running typechecker on this rightfully complained about > src/ImageRunModal.jsx(1062,51): error TS2740: > Type '{}' is missing the following properties from type '{ id: any; item: any; ... Change this to specify the type, so that it can be instantiated properly with `React.createElement()`. Existing callers in podman/machines have to be changed to <DynamicListForm ... itemcomponent={PublishPort} />
1 parent 5d3ac37 commit 8d65c82

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

pkg/lib/cockpit-components-dynamic-list.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import './cockpit-components-dynamic-list.scss';
1313
* - emptyStateString
1414
* - onChange
1515
* - id
16-
* - itemcomponent
16+
* - itemcomponent (React element type)
1717
* - formclass (optional)
1818
* - options (optional)
1919
* - onValidationChange: A handler function which updates the parent's component's validation object.
@@ -86,7 +86,7 @@ export class DynamicListForm extends React.Component {
8686
if (item === undefined)
8787
return null;
8888

89-
return React.cloneElement(this.props.itemcomponent, {
89+
return React.createElement(this.props.itemcomponent, {
9090
idx,
9191
item,
9292
id: id + "-" + idx,
@@ -135,7 +135,7 @@ DynamicListForm.propTypes = {
135135
emptyStateString: PropTypes.string.isRequired,
136136
onChange: PropTypes.func.isRequired,
137137
id: PropTypes.string.isRequired,
138-
itemcomponent: PropTypes.object.isRequired,
138+
itemcomponent: PropTypes.elementType.isRequired,
139139
formclass: PropTypes.string,
140140
options: PropTypes.object,
141141
validationFailed: PropTypes.array,

0 commit comments

Comments
 (0)