Skip to content

Commit ff20232

Browse files
committed
docs(examples): fix infinite scroll example to stop loading when it should
Closes TanStack#766
1 parent 2e4e941 commit ff20232

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

examples/load-more-infinite-scroll/hooks/useIntersectionObserver.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@ export default function useIntersectionObserver({
66
onIntersect,
77
threshold = 1.0,
88
rootMargin = '0px',
9+
enabled = true,
910
}) {
1011
React.useEffect(() => {
12+
if (!enabled) {
13+
return
14+
}
15+
1116
const observer = new IntersectionObserver(
1217
entries =>
1318
entries.forEach(entry => entry.isIntersecting && onIntersect()),
@@ -29,5 +34,5 @@ export default function useIntersectionObserver({
2934
return () => {
3035
observer.unobserve(el)
3136
}
32-
}, [target.current])
37+
}, [target.current, enabled])
3338
}

examples/load-more-infinite-scroll/pages/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export default () => {
3434
useIntersectionObserver({
3535
target: loadMoreButtonRef,
3636
onIntersect: fetchMore,
37+
enabled: canFetchMore,
3738
})
3839

3940
return (

0 commit comments

Comments
 (0)