Skip to content

Function: onMediaQuery()

onMediaQuery(mediaQueryString): Stream<boolean>

Defined in: streams/onMediaQuery.ts:19

Creates a reactive stream that emits true or false whenever a CSS media query matches or stops matching.

This stream allows you to reactively track viewport changes, orientation, or other media features in a consistent, subscription-based way.

Behavior:

  • The initial match status is emitted immediately upon subscription.
  • Subsequent changes are emitted whenever the media query's match state changes.
  • Each subscriber has its own listener, which is cleaned up when unsubscribing.

Parameters

mediaQueryString

string

A valid CSS media query string (e.g., "(min-width: 600px)").

Returns

Stream<boolean>

A stream emitting true if the query matches, false otherwise.

Released under the MIT License.