ziko-wrapper
Version:
integrate zikojs elements within other ui framework like vue react solidjs svelte astro ...
25 lines (23 loc) • 904 B
JSX
import { useRef, useEffect } from "preact/hooks";
export function DomWrapper({ children, engine, wrapper}) {
const containerRef = useRef(null);
useEffect(() => {
if (containerRef.current) {
containerRef.current.innerHTML = "";
const childrenArray = Array.isArray(children) ? children : [children];
childrenArray.forEach((child) => {
const {type, props} = child
const element = type.call(this, props)
if (element instanceof HTMLElement) containerRef.current.appendChild(element);
});
}
}, [children]);
return (
<div
{...(engine && { "data-engine": engine})}
{...(wrapper && { "data-wrapper": wrapper})}
ref={containerRef}
style={{display : "contents"}}
></div>
);
}