Skip to content

Commit

Permalink
Merge pull request #83 from danskernesdigitalebibliotek/DDFBRA-291-in…
Browse files Browse the repository at this point in the history
…finity-scroll-bug

feat: make the loadmore ref trigger 500px before the end of the list
  • Loading branch information
ThomasGross authored Dec 30, 2024
2 parents 84046c2 + a37650d commit f3d5a1d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions components/pages/searchPageLayout/SearchPageLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import useSearchMachineActor from "@/lib/machines/search/useSearchMachineActor"

const SearchPageLayout = () => {
const loadMoreRef = useRef(null)
const isInView = useInView(loadMoreRef)
const loadMoreRefIsInView = useInView(loadMoreRef)
const actor = useSearchMachineActor()
const {
data,
Expand All @@ -27,13 +27,13 @@ const SearchPageLayout = () => {
} = useSearchDataAndLoadingStates()

useEffect(() => {
if (isInView) {
if (loadMoreRefIsInView) {
actor.send({ type: "LOAD_MORE" })
}
// We choose to ignore the eslint warning below
// because we do not want to add the handleMore callback which changes on every render.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isInView])
}, [loadMoreRefIsInView])

useEffect(() => {
actor.send({ type: "RESET_BOOTSTRAP_STATE" })
Expand Down Expand Up @@ -100,7 +100,7 @@ const SearchPageLayout = () => {
)}
</>
)}
<div ref={loadMoreRef} className="h-0 opacity-0"></div>
<div ref={loadMoreRef} className="h-0 -translate-y-[500px] opacity-0"></div>
</div>
)
}
Expand Down

0 comments on commit f3d5a1d

Please sign in to comment.