Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make the loadmore ref trigger 500px before the end of the list #83

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading