Skip to content

fix key warnings #438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/client/packages/idom-client-react/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "idom-client-react",
"description": "A client for IDOM implemented in React",
"version": "0.8.3",
"version": "0.8.4",
"author": "Ryan Morshead",
"license": "MIT",
"type": "module",
Expand Down
35 changes: 19 additions & 16 deletions src/client/packages/idom-client-react/src/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,14 @@ export function Layout({ saveUpdateHook, sendEvent, loadImportSource }) {
}
}

export function Element({ model, key }) {
export function Element({ model }) {
if (model.importSource) {
return html`<${ImportedElement} model=${model} />`;
} else {
return html`<${StandardElement} model=${model} />`;
}
}

export function elementChildren(modelChildren) {
if (!modelChildren) {
return [];
} else {
return modelChildren.map((child) => {
switch (typeof child) {
case "object":
return html`<${Element} key=${child.key} model=${child} />`;
case "string":
return child;
}
});
}
}

function StandardElement({ model }) {
const config = react.useContext(LayoutConfigContext);
const children = elementChildren(model.children);
Expand Down Expand Up @@ -116,6 +101,24 @@ function ImportedElement({ model }) {
}
}

export function elementChildren(modelChildren) {
if (!modelChildren) {
return [];
} else {
return modelChildren.map((child, index) => {
switch (typeof child) {
case "object":
return html`<${Element}
key=${child.key || index.toString()}
model=${child}
/>`;
case "string":
return child;
}
});
}
}

function elementAttributes(model, sendEvent) {
const attributes = Object.assign({}, model.attributes);

Expand Down