@@ -4,7 +4,11 @@ import {
44 cancelIdleCallback ,
55} from './request-idle-callback'
66
7- type UseIntersectionObserverInit = Pick < IntersectionObserverInit , 'rootMargin' >
7+ type UseIntersectionObserverInit = Pick <
8+ IntersectionObserverInit ,
9+ 'rootMargin' | 'root'
10+ > //added 'root' as a property
11+
812type UseIntersection = { disabled ?: boolean } & UseIntersectionObserverInit
913type ObserveCallback = ( isVisible : boolean ) => void
1014type Observer = {
@@ -16,6 +20,8 @@ type Observer = {
1620const hasIntersectionObserver = typeof IntersectionObserver !== 'undefined'
1721
1822export function useIntersection < T extends Element > ( {
23+ //added 'root' as an option
24+ root,
1925 rootMargin,
2026 disabled,
2127} : UseIntersection ) : [ ( element : T | null ) => void , boolean ] {
@@ -37,11 +43,11 @@ export function useIntersection<T extends Element>({
3743 unobserve . current = observe (
3844 el ,
3945 ( isVisible ) => isVisible && setVisible ( isVisible ) ,
40- { rootMargin }
46+ { root , rootMargin } //added 'root' as an option
4147 )
4248 }
4349 } ,
44- [ isDisabled , rootMargin , visible ]
50+ [ isDisabled , root , rootMargin , visible ] //added 'root' as a dependency
4551 )
4652
4753 useEffect ( ( ) => {
0 commit comments