signal-desktop/ts/hooks/usePortal.ts
2023-01-03 11:55:46 -08:00

21 lines
483 B
TypeScript

// Copyright 2019 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { useEffect, useState } from 'react';
export function usePortal(): HTMLDivElement | null {
const [root, setRoot] = useState<HTMLDivElement | null>(null);
useEffect(() => {
const div = document.createElement('div');
document.body.appendChild(div);
setRoot(div);
return () => {
document.body.removeChild(div);
setRoot(null);
};
}, []);
return root;
}