|
Download react-use/docs/useIntersection.md from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/react-use/docs/useIntersection.md
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/react-use/docs/useIntersection.md
-
curl -L -o useIntersection.md https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/react-use/docs/useIntersection.md
1 kB
useIntersection
React sensor hook that tracks the changes in the intersection of a target element with an ancestor element or with a top-level document's viewport. Uses the Intersection Observer API and returns a IntersectionObserverEntry.
Usage
import * as React from 'react';
import { useIntersection } from 'react-use';
const Demo = () => {
const intersectionRef = React.useRef(null);
const intersection = useIntersection(intersectionRef, {
root: null,
rootMargin: '0px',
threshold: 1
});
return (
<div ref={intersectionRef}>
{intersection && intersection.intersectionRatio < 1
? 'Obscured'
: 'Fully in view'}
</div>
);
};
Reference
useIntersection(
ref: RefObject<HTMLElement>,
options: IntersectionObserverInit,
): IntersectionObserverEntry | null;