react-on-intersect
React hook to do something when two elements intersect.
Hooks are an upcoming feature that lets you use state and other React features without writing a class. They’re currently in React v16.7.0-alpha.
Demo
Installation
npm install react-on-intersect
Usage
{ const element = { console } { console } return <> <h1 ref=element style= marginTop: '110vh' textAlign: 'center' fontSize: '4em' > Hello Intersect! </h1> </> }
API
useIntersect({ onEnter, [onExit], element, [options] })
onEnter([entry])
A function which is called when elements start intersecting.
onExit([entry])
A function which is called when elements stop intersecting.
element
Target element to watch.
options
See Intersection Observer#Parameters for available options.