UNPKG

preact-intersection-observer

Version:

A lightweight Preact implementation of Intersection Observer API

21 lines (20 loc) 853 B
import { Ref, JSX, ComponentChildren, FunctionalComponent } from "preact"; export type Entry = IntersectionObserverEntry | undefined; export type InView = boolean; export type TriggerOnce = boolean; export interface ObserverOptions { rootMargin?: IntersectionObserverInit["rootMargin"]; threshold?: IntersectionObserverInit["threshold"]; defaultInView?: InView; triggerOnce?: TriggerOnce; } export declare const useObserver: <T extends HTMLElement>(options?: ObserverOptions) => [ref: Ref<T>, inView: boolean, entry: IntersectionObserverEntry]; export interface ViewportObserverProps { render: (props: { inView: InView; entry: Entry; }) => ComponentChildren; options?: ObserverOptions; as?: keyof JSX.IntrinsicElements; } export declare const ViewportObserver: FunctionalComponent<ViewportObserverProps>;