Skip to content
0

katanakit-js / useObserverCreate

Function: useObserverCreate() ​

ts
function useObserverCreate(
   key, 
   callback, 
   options?, 
   autoUnobserve?
): void;

Defined in: src/infrastructure/observer/observer.service.ts:70

Creates an IntersectionObserver under the given key. If an observer with the same key already exists, it is disconnected first.

Parameters ​

ParameterTypeDefault valueDescription
keystringundefinedA unique identifier for this observer.
callbackObserverCallbackundefinedInvoked when an observed element enters the viewport.
optionsIntersectionObserverInit...IntersectionObserver options (default: { threshold: 0.1 }).
autoUnobservebooleantrueWhether to automatically unobserve after first intersection (default: true).

Returns ​

void

Example ​

ts
useObserverCreate("hero", (entry) => {
  console.log("Hero is visible!", entry.target);
}, { threshold: 0.5 });

Released under the MIT License.