@lifarl/react-scroll-snap-slider
Version:
A React Slider / Carousel Component with Scroll Snapping and Intersection Observer. ***[Demo](https://lifarl.github.io/react-scroll-snap-slider/)***
19 lines (18 loc) • 470 B
text/typescript
export const getObserver = (
root: HTMLDivElement | null = null,
ref: React.MutableRefObject<IntersectionObserver | null>,
callback: (entries: IntersectionObserverEntry[]) => void,
threshold: number
) => {
const observer = ref.current
if (observer !== null) {
return observer
}
const newObserver = new IntersectionObserver(callback, {
root,
rootMargin: '0px',
threshold: threshold,
})
ref.current = newObserver
return newObserver
}