mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-27 10:32:58 +02:00
0edc66da49
Relates to #5389
18 lines
507 B
TypeScript
18 lines
507 B
TypeScript
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) => {
|
|
const element = await waitForElement(document, elementId);
|
|
if (event.cancelled) return;
|
|
setRootElement(element);
|
|
}, [document, elementId]);
|
|
|
|
return rootElement;
|
|
};
|
|
|
|
export default useRootElement;
|