@supunlakmal/hooks
Version:
A collection of reusable React hooks
12 lines (11 loc) • 630 B
TypeScript
import { RefObject } from 'react';
/**
* A hook that tracks if an element has ever become visible in the viewport.
* Uses useIntersectionObserver internally. Once the element is visible,
* the hook consistently returns true, even if it scrolls out of view later.
*
* @param elementRef The React ref attached to the element to observe.
* @param observerOptions Optional options for the IntersectionObserver.
* @returns `true` if the element has been visible at least once, `false` otherwise.
*/
export declare function useHasBeenVisible(elementRef: RefObject<Element>, observerOptions?: IntersectionObserverInit): boolean;