Merge pull request #207 from omnivore-app/fix/first-react-state

Use react state for first flag when fetching
This commit is contained in:
Jackson Harper 2022-03-09 09:49:43 -08:00 committed by GitHub
commit adb8158b66
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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])
}