MCPcopy
hub / github.com/pmndrs/react-spring / handleIntersection

Function handleIntersection

packages/core/src/hooks/useInView.ts:87–107  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

85 }
86
87 const handleIntersection: IntersectionObserverCallback = entries => {
88 entries.forEach(entry => {
89 const onLeave = activeIntersections.get(entry.target)
90
91 if (entry.isIntersecting === Boolean(onLeave)) {
92 return
93 }
94
95 if (entry.isIntersecting) {
96 const newOnLeave = onEnter()
97 if (is.fun(newOnLeave)) {
98 activeIntersections.set(entry.target, newOnLeave)
99 } else {
100 observer.unobserve(entry.target)
101 }
102 } else if (onLeave) {
103 onLeave()
104 activeIntersections.delete(entry.target)
105 }
106 })
107 }
108
109 const observer = new IntersectionObserver(handleIntersection, {
110 root: (root && root.current) || undefined,

Callers

nothing calls this directly

Calls 5

onEnterFunction · 0.85
forEachMethod · 0.80
deleteMethod · 0.80
getMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…