npm install --save use-intersect
import * as React from 'react'
import useIntersect from 'use-intersect'
const option = {
threshold: 0.8
}
const handleIntersect = (targetElement) ={
console.log('intersect', targetElement)
}
const Example = () => {
const targetRef = useIntersect(handleIntersect, {rootOptions: option, once:true})
return (
<img ref={targetRef}/>
)
}
Prop |
Type |
Required |
Description |
onIntersect |
Function |
✓ |
Execute onItersect Function |
IntersectOptions |
IntersectOptions |
|
Intersect option |
name |
Type |
Required |
Description |
rootOptions |
ObserverOptions |
|
ObserverOptions |
once |
boolean |
|
[default:true] Trigger onItersect once |
name |
Type |
Required |
Description |
root |
Element | null |
|
root Element |
rootMargin |
string |
|
Observer rootMargin |
threshold |
number |
|
Observer threshold |
[MDN]Reference
MIT © 🐭snyung