ilokesto

Observer

Observer uses IntersectionObserver through useIntersectionObserver and renders its children only when the observed div is intersecting.

import { Observer } from '@ilokesto/utilinent';

<Observer fallback={<CardPlaceholder />} rootMargin="120px" triggerOnce>
  <ExpensiveCard />
</Observer>

Props

PropTypeDescription
childrenReactNode | (isIntersecting) => ReactNodeContent rendered while intersecting.
fallbackReactNodeRendered while not intersecting.
thresholdnumber | number[]Intersection threshold. Defaults to 0.
rootMarginstringObserver root margin. Defaults to "0%".
triggerOncebooleanStop observing after first intersection.
onIntersect(isIntersecting, entry) => voidCalled when entering intersection after initial observation.
keepMeasurablebooleanForce a minimum 1×1px measurable box and display: block so the element can be observed even without content. Defaults to false.

Observer renders through Show.div, so the observed element is a div and accepts normal div props/ref.

On this page