import React, { useMemo, useLayoutEffect } from "react"; import { createPortal } from "react-dom"; type Props = { children: { [id: string]: string[] }; }; // this.props.children should be an object containing arrays of strings. The // keys are ids, and the arrays are arrays of polygon point strings export default function ClipPaths({ children }: Props) { const paths = useMemo(() => { return document.createElement("div"); }, []); useLayoutEffect(() => { document.body.appendChild(paths); return () => paths.remove(); }, [paths]); return createPortal( {Object.keys(children).map(id => ( {children[id].map((points, i) => ( ))} ))} , paths ); }