diff --git a/.changeset/ten-icons-mix.md b/.changeset/ten-icons-mix.md new file mode 100644 index 0000000..6a9ea26 --- /dev/null +++ b/.changeset/ten-icons-mix.md @@ -0,0 +1,5 @@ +--- +"@virtual-grid/react": patch +--- + +fix rerender issue diff --git a/packages/react/src/useGrid.tsx b/packages/react/src/useGrid.tsx index c43edd2..4db2fc5 100644 --- a/packages/react/src/useGrid.tsx +++ b/packages/react/src/useGrid.tsx @@ -33,6 +33,8 @@ export const useGrid = < const { scrollRef, overscan, onLoadMore, loadMoreSize, ...options } = props; const { getItemId, getItemData, invert, ...measureOptions } = options; + const rerender = React.useReducer(() => ({}), {})[1]; + const [gridWidth, setGridWidth] = React.useState(0); const [gridHeight, setGridHeight] = React.useState(0); @@ -48,7 +50,10 @@ export const useGrid = < setOptions({ ...options, width, height }); // Measure grid when options that require a measure change - useDeepCompareMemo(measure, [measure, measureOptions, width, height]); + useDeepCompareMemo(() => { + measure(); + rerender(); + }, [measure, rerender, measureOptions, width, height]); // Check if grid size should be observed const observeGrid = observeGridSize(props);