Skip to main content

useIntersection

Purpose

The useIntersection hook allows you to observe the intersection of a target element with an ancestor element or with a top-level document's viewport.

This behavior is built on top of the Intersection Observer API. See Intersection Observer API for more information.

Side Effects

The useIntersection hook will create an IntersectionObserver instance when the hook is called. The IntersectionObserver instance will be destroyed when the component unmounts.

Usage

useIntersection

ParametersTypePurposeDefault
controllerControllerThe instance of the controller to install the behaviour on. This allows the mixin to automatically register cleanup on the controller's disconnect.this
elementHTMLElementThe element to observe.
appear (Optional)FunctionThe callback to invoke when the element scrolls into the viewport. Accepts a single parameter of type IntersectionObserverEntry
disappear (Optional)FunctionThe callback to invoke when the element scrolls out of the viewport. Accepts a single parameter of type IntersectionObserverEntry
options (Optional)IntersectionObserverInitThe raw options to pass to initialize the IntersectionObserver