2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2019 Signal Messenger, LLC
|
2021-12-01 02:14:25 +00:00
|
|
|
// 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;
|
|
|
|
}
|