Skip to content

Commit

Permalink
Merge pull request #88 from wellyshen/fix/ssr-items-size
Browse files Browse the repository at this point in the history
Fix: fallback tp default item size for SSR items
  • Loading branch information
wellyshen authored Jun 2, 2021
2 parents 0acdc4f + b5d483d commit 7c61cf3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/young-waves-approve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"react-cool-virtual": patch
---

fix: fallback tp default item size for SSR items
10 changes: 5 additions & 5 deletions src/useVirtual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const getInitItems = (itemSize: ItemSize, ssrItemCount?: SsrItemCount) => {
index: i,
start: 0,
width: 0,
size: isNumber(itemSize) ? itemSize : itemSize(i, 0),
size: isNumber(itemSize) ? itemSize : itemSize(i, 0) ?? DEFAULT_ITEM_SIZE,
measureRef: () => null,
};

Expand Down Expand Up @@ -97,10 +97,10 @@ export default <

const getItemSize = useCallback(
(idx: number) => {
let { current: size } = itemSizeRef;
size = isNumber(size) ? size : size(idx, outerRectRef.current.width);

return size ?? DEFAULT_ITEM_SIZE;
const { current: size } = itemSizeRef;
return isNumber(size)
? size
: size(idx, outerRectRef.current.width) ?? DEFAULT_ITEM_SIZE;
},
[itemSizeRef]
);
Expand Down

0 comments on commit 7c61cf3

Please sign in to comment.