React visibility detector
A React component that notifies you when it enters or exits the viewport. Based on a IntersectionObserver, resulting in improved performance.
Install
yarn add react-visibility-detector
Example
To run the example locally:
yarn build
cd example
yarn
yarn start
- open
http://localhost:1234
in your browser
General usage goes something like:
Props
className
css class for styling, defaultundefined
distance
- distance to the viewport at which the detector will trigger, default0
onVisibilityChange
- callback, called when changed detector visibilitychildren
Hook props
distance
- distance to the viewport at which the detector will trigger, default0
onVisibilityChange
- callback, called when changed detector visibilitytargetRef
- ref to target element