Skip to content

Commit

Permalink
fix render issue (#19)
Browse files Browse the repository at this point in the history
* fix render issue

* Create ten-icons-mix.md
  • Loading branch information
niikeec authored May 28, 2024
1 parent 78b7ed4 commit cd26778
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/ten-icons-mix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@virtual-grid/react": patch
---

fix rerender issue
7 changes: 6 additions & 1 deletion packages/react/src/useGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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 warning on line 56 in packages/react/src/useGrid.tsx

View workflow job for this annotation

GitHub Actions / Release

React Hook useDeepCompareMemo has unnecessary dependencies: 'height', 'measureOptions', and 'width'. Either exclude them or remove the dependency array

// Check if grid size should be observed
const observeGrid = observeGridSize(props);
Expand Down

0 comments on commit cd26778

Please sign in to comment.