You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gcgj-dify-1.7.0/web/app/components/plugins/marketplace/hooks.ts

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])
}