mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 00:03:33 +10:00
19 lines
483 B
TypeScript
19 lines
483 B
TypeScript
import { useEffect, useState } from 'react';
|
|
|
|
import { createPortal } from 'react-dom';
|
|
|
|
type PortalComponentProps = {
|
|
children: React.ReactNode;
|
|
target: string;
|
|
};
|
|
|
|
export const PortalComponent = ({ children, target }: PortalComponentProps) => {
|
|
const [portalRoot, setPortalRoot] = useState<HTMLElement | null>(null);
|
|
|
|
useEffect(() => {
|
|
setPortalRoot(document.getElementById(target));
|
|
}, [target]);
|
|
|
|
return portalRoot ? createPortal(children, portalRoot) : null;
|
|
};
|