UNPKG

use-element-in-view

Version:

A simple React hook to track whether an element is visible in the viewport with the Intersection Observer. This API provides a native way to asynchronously observe changes in the intersection of a target element with an ancestor element or with a top-leve

19 lines (18 loc) 847 B
/// <reference types="jest" /> interface MockedIntersectionObserverCallback { (entries: MockedIntersectionObserverEntry[], observer?: IntersectionObserver): void; } interface MockedIntersectionObserverEntry { target: HTMLElement; intersectionRatio?: number | number[]; isIntersecting?: boolean; } export declare const observerMap: Map<IntersectionObserver, ObserverItem>; declare type ObserverItem = { callback: MockedIntersectionObserverCallback; element: Set<HTMLElement>; }; export declare const mockIntersectionObserver: jest.Mock<IntersectionObserver, [any, any?]>; export declare function triggerObserverCallback({ target, isIntersecting, intersectionRatio, }: MockedIntersectionObserverEntry): void; export declare function getMockedInstance(element: HTMLElement): IntersectionObserver; export {};