fix: window scroller grid remeasure on size change

This commit is contained in:
sk1982 2024-04-13 02:26:48 -04:00
parent bf653849d6
commit 43ab38db72

View File

@ -1,4 +1,4 @@
import { ReactNode, useRef } from 'react'; import { ReactNode, useEffect, useRef } from 'react';
import { useWindowVirtualizer } from '@tanstack/react-virtual'; import { useWindowVirtualizer } from '@tanstack/react-virtual';
import { useResizeObserver } from 'usehooks-ts'; import { useResizeObserver } from 'usehooks-ts';
@ -26,6 +26,10 @@ export const WindowScrollerGrid = <D extends any>({ rowSize, colSize, items, chi
overscan: 5, overscan: 5,
scrollingDelay: 0 scrollingDelay: 0
}); });
useEffect(() => {
virtualizer.measure();
}, [rowSize, colSize, virtualizer]);
return (<div ref={listRef} className={width <= 0 ? `invisible` : ''}> return (<div ref={listRef} className={width <= 0 ? `invisible` : ''}>
{width > 0 && <div className="w-full relative" style={{ {width > 0 && <div className="w-full relative" style={{