mirror of
https://github.com/hanzoai/sentinel.git
synced 2026-10-30 14:49:14 +00:00
26 lines
631 B
TypeScript
26 lines
631 B
TypeScript
import type {RefObject} from 'react';
|
|
import {useCallback} from 'react';
|
|
import type {CellMeasurerCache, List} from 'react-virtualized';
|
|
|
|
type Opts = {
|
|
cache: CellMeasurerCache;
|
|
listRef: RefObject<List>;
|
|
};
|
|
|
|
export type OnDimensionChange = (index: number) => void;
|
|
|
|
export default function useVirtualListDimentionChange({cache, listRef}: Opts) {
|
|
const handleDimensionChange = useCallback(
|
|
(index: number) => {
|
|
cache.clear(index, 0);
|
|
listRef.current?.recomputeGridSize({rowIndex: index});
|
|
listRef.current?.forceUpdateGrid();
|
|
},
|
|
[cache, listRef]
|
|
);
|
|
|
|
return {
|
|
handleDimensionChange,
|
|
};
|
|
}
|