forked from
did:plc:2hcnfmbfr4ucfbjpnvjqvt3e/bbell
wip bsky client for the web & android
1import { onBeforeUnmount } from 'vue'
2
3export function useInfiniteScroll(
4 sentinelRef: { value: HTMLElement | null },
5 onIntersect: () => void,
6 opts = { rootMargin: '200px', threshold: 0.1 },
7) {
8 let obs: IntersectionObserver | null = null
9 const setup = () => {
10 if (!sentinelRef.value) return
11 obs = new IntersectionObserver((entries) => {
12 for (const e of entries) if (e.isIntersecting) onIntersect()
13 }, opts)
14 obs.observe(sentinelRef.value)
15 }
16 onBeforeUnmount(() => {
17 if (obs && sentinelRef.value) obs.unobserve(sentinelRef.value)
18 obs = null
19 })
20 return { setup }
21}