1 import type { ReactNode, ReactPortal } from 'react';
2 import { useMemo, useRef } from 'react';
3 import { createPortal } from 'react-dom';
5 import type { MaybeNull } from '@proton/pass/types';
8 ParentPortal: ReactNode;
9 openPortal: (children: ReactNode) => MaybeNull<ReactPortal>;
12 export const usePortal = (): UsePortalType => {
13 const ref = useRef<HTMLDivElement>(null);
16 ParentPortal: useMemo(() => <div ref={ref} />, []),
17 openPortal: (children) => (ref.current ? createPortal(children, ref.current) : null),