Skip to content

Commit

Permalink
fix(ui): fix infinite scroll flickering
Browse files Browse the repository at this point in the history
  • Loading branch information
ncarlier committed May 16, 2019
1 parent cc5c322 commit ae083f9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ui/src/articles/components/ArticleList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default (props: Props) => {
const [articles, setArticles] = useState(props.articles.filter(filter))
const [activeIndex, setActiveIndex] = useState(0)

const isFetching = useInfiniteScroll(ref, fetchMoreArticles)
const isFetching = useInfiniteScroll(ref, hasMore, fetchMoreArticles)
const isMobileDisplay = useMedia('(max-width: 767px)')

useKeyNavigation(ref, styles.item, !isMobileDisplay)
Expand Down
6 changes: 3 additions & 3 deletions ui/src/hooks/useInfiniteScroll.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { RefObject, useCallback, useEffect, useState } from 'react'

export default (ref: RefObject<HTMLElement>, fetchMoreItems: () => Promise<void>): boolean => {
export default (ref: RefObject<HTMLElement>, hasMore: boolean, fetchMoreItems: () => Promise<void>): boolean => {
const [isFetching, setIsFetching] = useState(false)

useEffect(() => {
Expand All @@ -20,7 +20,7 @@ export default (ref: RefObject<HTMLElement>, fetchMoreItems: () => Promise<void>
}, [isFetching, ref])

useEffect(() => {
if (!ref.current) {
if (!ref.current || !hasMore) {
return
}
const $container = ref.current.parentElement
Expand All @@ -32,7 +32,7 @@ export default (ref: RefObject<HTMLElement>, fetchMoreItems: () => Promise<void>
$container.removeEventListener('resize', handleScroll)
}
}
}, [ref])
}, [ref, hasMore])

return isFetching
}

0 comments on commit ae083f9

Please sign in to comment.