useIntersectionObserver
Custom hook that tracks the intersection of a DOM element with its containing element or the viewport using the [
Intersection Observer API](https://developer.Installation
npx sse-tool add use-intersection-observer
npm install sse-hooks
Usage
import { useIntersectionObserver } from "./{hooks file}";
// Example 1
const [ref, isIntersecting, entry] = useIntersectionObserver({
threshold: 0.5,
});
// Example 2
const { ref, isIntersecting, entry } = useIntersectionObserver({
threshold: 0.5,
});
import { useIntersectionObserver } from "sse-hooks";
// Example 1
const [ref, isIntersecting, entry] = useIntersectionObserver({
threshold: 0.5,
});
// Example 2
const { ref, isIntersecting, entry } = useIntersectionObserver({
threshold: 0.5,
});
API
Parameters
| Name | Type | Description |
|---|---|---|
| options | UseIntersectionObserverOptions | The options for the Intersection Observer. |
Return Value
Returns IntersectionReturn.
The ref callback, a boolean indicating if the element is intersecting, and the intersection observer entry.