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