Extract key from props in h() for UElement, keep key in props for URoot
This commit is contained in:
@@ -3,18 +3,19 @@ import type { UNode, UElement, URoot, UType, UComponent, UniversalProps } from "
|
||||
let _idCounter = 0;
|
||||
|
||||
export function h(type: UType, props?: UniversalProps | null, ...children: UNode[]): UElement | URoot {
|
||||
const { key, ...restProps } = props ?? {};
|
||||
const resolvedProps: UniversalProps = restProps;
|
||||
const flatChildren = children.flat(Infinity as 1).filter((c: UNode) => c != null && c !== false) as UNode[];
|
||||
|
||||
if (type === "root") {
|
||||
return {
|
||||
type: "root",
|
||||
props: resolvedProps,
|
||||
props: { ...(props ?? {}) },
|
||||
children: flatChildren,
|
||||
} as URoot;
|
||||
}
|
||||
|
||||
const { key, ...restProps } = props ?? {};
|
||||
const resolvedProps: UniversalProps = restProps;
|
||||
|
||||
return {
|
||||
type: type as string,
|
||||
props: resolvedProps,
|
||||
|
||||
Reference in New Issue
Block a user