mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Merge pull request #207 from omnivore-app/fix/first-react-state
Use react state for first flag when fetching
This commit is contained in:
commit
adb8158b66
1 changed files with 3 additions and 3 deletions
|
|
@ -19,7 +19,7 @@ export const useFetchMoreScroll = (
|
|||
}
|
||||
|
||||
const useFetchMoreInternal = (node: HTMLDivElement | null, callback: () => void, delay = 500): void => {
|
||||
let first = false
|
||||
const [first, setFirst] = useState(true)
|
||||
const throttleTimeout = useRef<NodeJS.Timeout | undefined>(undefined)
|
||||
|
||||
useEffect(() => {
|
||||
|
|
@ -42,7 +42,7 @@ const useFetchMoreInternal = (node: HTMLDivElement | null, callback: () => void,
|
|||
|
||||
const handleScroll = () => {
|
||||
if (first) {
|
||||
first = false
|
||||
setFirst(false)
|
||||
callbackInternal()
|
||||
return
|
||||
}
|
||||
|
|
@ -56,5 +56,5 @@ const useFetchMoreInternal = (node: HTMLDivElement | null, callback: () => void,
|
|||
return () => {
|
||||
node.removeEventListener('scroll', handleScroll)
|
||||
}
|
||||
}, [node, callback, delay])
|
||||
}, [node, callback, delay, first, setFirst])
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue