UNPKG

ziko-wrapper

Version:

integrate zikojs elements within other ui framework like vue react solidjs svelte astro ...

30 lines (26 loc) 1.03 kB
import { render } from "preact"; import { useRef, useEffect } from "preact/hooks"; export function ZikoWrapper({ children }) { const containerRef = useRef(null); useEffect(() => { if (containerRef.current) { containerRef.current.innerHTML = ""; const childrenArray = Array.isArray(children) ? children : [children]; childrenArray.forEach((child) => { const childWithProps = { ...child, props: { ...child.props } }; const childElement = render(childWithProps, containerRef.current, containerRef.current.firstChild); if (childElement instanceof HTMLElement) { containerRef.current.appendChild(childElement); } }); } }, [children]); return ( <div data-wrapper="ziko-wrapper" data-engine="ziko.js" ref={containerRef} style={{display : "contents"}} ></div> ); }