mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-07-09 10:01:47 +08:00
22 lines
683 B
TypeScript
22 lines
683 B
TypeScript
import { useEffect } from 'react'
|
|
|
|
export const useScrollIntersection = (
|
|
containerRef: React.RefObject<HTMLDivElement>,
|
|
anchorRef: React.RefObject<HTMLDivElement>,
|
|
callback: (isIntersecting: boolean) => void,
|
|
) => {
|
|
useEffect(() => {
|
|
let observer: IntersectionObserver | undefined
|
|
if (containerRef?.current && anchorRef.current) {
|
|
observer = new IntersectionObserver((entries) => {
|
|
const isIntersecting = entries[0].isIntersecting
|
|
callback(isIntersecting)
|
|
}, {
|
|
root: containerRef.current,
|
|
})
|
|
observer.observe(anchorRef.current)
|
|
}
|
|
return () => observer?.disconnect()
|
|
}, [containerRef, anchorRef, callback])
|
|
}
|