1fa55bfd02
Fixing a few bugs: - CommandMenu not reactive - Filtering on index view infinite loop
33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
import { useCallback } from 'react';
|
|
|
|
import { ScrollWrapperComponentInstanceContext } from '@/ui/utilities/scroll/states/contexts/ScrollWrapperComponentInstanceContext';
|
|
import { useAvailableComponentInstanceIdOrThrow } from '@/ui/utilities/state/component-state/hooks/useAvailableComponentInstanceIdOrThrow';
|
|
import { useHTMLElementByIdWhenAvailable } from '~/hooks/useHTMLElementByIdWhenAvailable';
|
|
|
|
export const useScrollWrapperHTMLElement = (
|
|
targetComponentInstanceId?: string,
|
|
) => {
|
|
const instanceId = useAvailableComponentInstanceIdOrThrow(
|
|
ScrollWrapperComponentInstanceContext,
|
|
targetComponentInstanceId,
|
|
);
|
|
|
|
const scrollWrapperId = `scroll-wrapper-${instanceId}`;
|
|
|
|
const { element: scrollWrapperHTMLElement } =
|
|
useHTMLElementByIdWhenAvailable(scrollWrapperId);
|
|
|
|
const getScrollWrapperElement = useCallback(() => {
|
|
const scrollWrapperElement = document.getElementById(scrollWrapperId);
|
|
|
|
return {
|
|
scrollWrapperElement,
|
|
};
|
|
}, [scrollWrapperId]);
|
|
|
|
return {
|
|
scrollWrapperHTMLElement,
|
|
getScrollWrapperElement,
|
|
};
|
|
};
|