Skip to content

Commit a9a7bc7

Browse files
authored
Fixed automatic call of onIntersect function in infite-scroll example (#449)
1 parent d024134 commit a9a7bc7

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@ export default function useIntersectionObserver({
88
rootMargin = '0px',
99
}) {
1010
React.useEffect(() => {
11-
const observer = new IntersectionObserver(onIntersect, {
12-
root: root && root.current,
13-
rootMargin,
14-
threshold,
15-
})
11+
const observer = new IntersectionObserver(
12+
entries =>
13+
entries.forEach(entry => entry.isIntersecting && onIntersect()),
14+
{
15+
root: root && root.current,
16+
rootMargin,
17+
threshold,
18+
}
19+
)
1620

1721
const el = target && target.current
1822

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export default () => {
3232

3333
useIntersectionObserver({
3434
target: loadMoreButtonRef,
35-
onIntersect: () => fetchMore(),
35+
onIntersect: fetchMore,
3636
})
3737

3838
return (

0 commit comments

Comments
 (0)