Skip to content

Commit

Permalink
add a warning if the user posted the wrong pair of props
Browse files Browse the repository at this point in the history
  • Loading branch information
vdmrgv committed Jun 28, 2022
1 parent b16693d commit 313ebfb
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/InfiniteScroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,22 @@ class InfiniteScroll {
columnCount: cachedColumnLength = 0,
isLoading: { start, end },
},
props: { rowCount = 0, columnCount = 0, reverse = {} },
props: { rowCount, columnCount, reverse = {}, hasMore },
_scrollingContainerRef,
} = this;

if (!_scrollingContainerRef) return;

if (rowCount === undefined && (hasMore.down || hasMore.up))
console.warn(
`You provided props with "hasMore: { up: ${!!hasMore.up}, down: ${!!hasMore.down} } but "rowCount" is "undefined"`
);

if (columnCount === undefined && (hasMore.left || hasMore.right))
console.warn(
`You provided props with "hasMore: { left: ${!!hasMore.left}, right: ${!!hasMore.right} } but "columnCount" is "undefined"`
);

const { scrollTop, scrollLeft, scrollHeight, scrollWidth, clientHeight, clientWidth } = _scrollingContainerRef;
const { column, row } = reverse;

Expand Down Expand Up @@ -279,7 +289,7 @@ class InfiniteScroll {
onScroll(scrollPosition + (newScrollSize - cachedScrollSize) * signMultiplier);
}

// if the download was successful
// if the download is over
if (loadComplete) {
onLoadComplete();
}
Expand All @@ -289,7 +299,7 @@ class InfiniteScroll {
scrollTop,
clientHeight,
cachedRowLength,
rowCount,
rowCount ?? 0,
this.state.scrollHeight,
scrollHeight,
(pos: number) => {
Expand Down Expand Up @@ -320,7 +330,7 @@ class InfiniteScroll {
scrollLeft,
clientWidth,
cachedColumnLength,
columnCount,
columnCount ?? 0,
this.state.scrollWidth,
scrollWidth,
(pos: number) => {
Expand Down

0 comments on commit 313ebfb

Please sign in to comment.