Update selected item color in Pass menu
[ProtonMail-WebClient.git] / packages / pass / hooks / usePortal.tsx
blobfee3da5ee72cbdc4512e68a980e371cc00094aff
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';
7 type UsePortalType = {
8     ParentPortal: ReactNode;
9     openPortal: (children: ReactNode) => MaybeNull<ReactPortal>;
12 export const usePortal = (): UsePortalType => {
13     const ref = useRef<HTMLDivElement>(null);
15     return {
16         ParentPortal: useMemo(() => <div ref={ref} />, []),
17         openPortal: (children) => (ref.current ? createPortal(children, ref.current) : null),
18     };