@supunlakmal/hooks
Version:
A collection of reusable React hooks
16 lines (15 loc) • 1.24 kB
TypeScript
import { RefObject } from 'react';
interface UseIntersectionObserverOptions extends IntersectionObserverInit {
}
/**
* Custom hook to track the visibility of an element within the viewport or a specified ancestor element.
*
* @param {RefObject<Element | null>} elementRef - The ref attached to the target element to observe.
* @param {UseIntersectionObserverOptions} [options] - Configuration options for the IntersectionObserver.
* @param {Element | null} [options.root=null] - The element that is used as the viewport for checking visibility. Defaults to the browser viewport.
* @param {string} [options.rootMargin='0px'] - Margin around the root. Can have values similar to the CSS margin property.
* @param {number | number[]} [options.threshold=0] - A single number or an array of numbers indicating at what percentage of the target's visibility the observer's callback should be executed.
* @returns {IntersectionObserverEntry | null} The latest IntersectionObserverEntry for the observed element, or null if not intersecting or not yet observed.
*/
export declare const useIntersectionObserver: (elementRef: RefObject<Element | null>, options?: UseIntersectionObserverOptions) => IntersectionObserverEntry | null;
export {};