Skip to content

Commit

Permalink
fix(useInfiniteScroll): fix not loading when it has more space to scr…
Browse files Browse the repository at this point in the history
…oll after first load
  • Loading branch information
vikiboss committed Sep 9, 2024
1 parent 37ddd58 commit c4036ca
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/react-use/src/use-infinite-scroll/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useMount } from '../use-mount'
import { useRafState } from '../use-raf-state'
import { useStableFn } from '../use-stable-fn'
import { useTargetElement } from '../use-target-element'
import { useUpdateEffect } from '../use-update-effect'

import type { ElementTarget } from '../use-target-element'

Expand Down Expand Up @@ -89,7 +90,10 @@ export function useInfiniteScroll<R = any, T extends HTMLElement = HTMLElement>(
const latest = useLatest({ state, canLoadMore, direction, onScroll, onLoadMore, interval })

const calculate = useStableFn(async () => {
if (!latest.current.canLoadMore(previousReturn.current)) return
if (!latest.current.canLoadMore(previousReturn.current)) {
setState({ isLoadDone: true, isLoading: false })
return
}

if (!el.current || latest.current.state.isLoading) return

Expand Down Expand Up @@ -121,6 +125,10 @@ export function useInfiniteScroll<R = any, T extends HTMLElement = HTMLElement>(

useMount(immediate && calculate)

useUpdateEffect(() => {
if (!state.isLoading) calculate()
}, [state.isLoading])

useEventListener(
el,
'scroll',
Expand Down

0 comments on commit c4036ca

Please sign in to comment.