mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-20 17:09:12 +08:00
hook
This commit is contained in:
parent
8dd941e3d2
commit
27ae74af50
20
web/app/components/plugins/marketplace/hooks.ts
Normal file
20
web/app/components/plugins/marketplace/hooks.ts
Normal file
@ -0,0 +1,20 @@
|
||||
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])
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user