2023-08-21 17:01:20 +02:00
|
|
|
import { useState } from 'react';
|
|
|
|
import useAsyncEffect from '@joplin/lib/hooks/useAsyncEffect';
|
|
|
|
import { waitForElement } from '@joplin/lib/dom';
|
|
|
|
|
|
|
|
const useRootElement = (elementId: string) => {
|
|
|
|
const [rootElement, setRootElement] = useState<HTMLDivElement>(null);
|
|
|
|
|
|
|
|
useAsyncEffect(async (event) => {
|
2024-09-27 16:25:55 +02:00
|
|
|
const element = await waitForElement(document, elementId, event);
|
2023-08-21 17:01:20 +02:00
|
|
|
if (event.cancelled) return;
|
|
|
|
setRootElement(element);
|
|
|
|
}, [document, elementId]);
|
|
|
|
|
|
|
|
return rootElement;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default useRootElement;
|