Highly ambitious ATProtocol AppView service and sdks
1import type { ComponentChildren, VNode } from "preact";
2import { cloneElement } from "preact";
3
4/**
5 * Passes props down to all children that accept them
6 */
7export function passPropsToChildren(
8 children: ComponentChildren,
9 props: Record<string, unknown>
10): ComponentChildren {
11 if (Array.isArray(children)) {
12 return children.map(child => {
13 if (child && typeof child === 'object' && 'type' in child) {
14 return cloneElement(child as VNode, props);
15 }
16 return child;
17 });
18 }
19
20 if (children && typeof children === 'object' && 'type' in children) {
21 return cloneElement(children as VNode, props);
22 }
23
24 return children;
25}