Skip to main content
Glama
renderSolidElement.ts1.31 kB
import type { JSX } from 'solid-js'; import { Dynamic } from 'solid-js/web'; // This function recursively creates Solid elements from a given JSON-like structure export const renderSolidElement = (element: JSX.Element) => { if (typeof element === 'string') { // If it's a string, simply return it (used for text content) return element; } const convertChildrenAsArray = (element: any): any => { if (element?.props && typeof element.props.children === 'object') { const childrenResult: JSX.Element[] = []; const { children } = element.props; // Create the children elements recursively, if any Object.keys(children ?? {}).forEach((key) => { childrenResult.push( renderSolidElement(children?.[key as keyof typeof children]) ); }); return { ...element, props: { ...element.props, children: childrenResult }, }; } return { ...element, props: { ...element.props, children: element.props?.children ?? [] }, }; }; const fixedElement = convertChildrenAsArray(element); const { type, props } = fixedElement; // Create and return the Solid element using Dynamic component return Dynamic({ component: type ?? 'span', ...props, children: props.children, }); };

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/aymericzip/intlayer'

If you have feedback or need assistance with the MCP directory API, please join our Discord server