import { useLayoutEffect, useRef } from 'react'; export type CommentProps = { children?: React.ReactNode; openComment?: string; closeComment?: string; }; /** * Used to render HTML comments needed for magnolia editor to work. */ export const Comment = ({ children, openComment, closeComment }: CommentProps) => { const openNode = useRef(null); const closeNode = useRef(null); useLayoutEffect(() => { if (openComment) { openNode.current?.insertAdjacentHTML( 'beforebegin', `` ); } if (closeComment) { closeNode.current?.insertAdjacentHTML( 'afterend', `` ); } }, [openComment, closeComment]); return ( <>
{children}
); };