Skip to content

@epikodelabs/streamix


@epikodelabs/streamix / dom/src/public-api / onResize

Function: onResize()

onResize(element): Stream<{ width: number; height: number; }>

Defined in: projects/libraries/streamix/dom/src/lib/streams/onResize.ts:21

Creates a reactive stream that emits the dimensions of a given DOM element whenever it is resized.

This stream is a wrapper around the ResizeObserver API.

Behavior:

  • Resolves the element once on first subscription.
  • Emits the current width and height whenever the element is resized.
  • Emits the initial size on start.
  • Starts observing on first subscriber.
  • Stops observing when the last subscriber unsubscribes.
  • Safe to import and subscribe in SSR (no-op).
  • Fully compatible with async iteration.

Parameters

element

MaybePromise<HTMLElement>

The DOM element (or promise) to observe.

Returns

Stream<{ width: number; height: number; }>

Released under the GNU AGPL v3 or later.