Files
archived-linsa/web/lib/utils/htmlLikeElementUtil.ts
Aslam f005101d91 feat: navigation for command palette (#150)
* feat: add dotenv to dev dep

* chore: jest use env

* feat

* feat: command palette navigation
2024-09-08 05:43:44 +07:00

22 lines
569 B
TypeScript

import React from "react"
export type HTMLAttributes = React.HTMLAttributes<HTMLElement> & {
[key: string]: any
}
export type HTMLLikeElement = {
tag: keyof JSX.IntrinsicElements
attributes?: HTMLAttributes
children?: (HTMLLikeElement | string)[]
}
export const renderHTMLLikeElement = (element: HTMLLikeElement | string): React.ReactNode => {
if (typeof element === "string") {
return element
}
const { tag, attributes = {}, children = [] } = element
return React.createElement(tag, attributes, ...children.map(child => renderHTMLLikeElement(child)))
}