@epikodelabs/streamix / dom/src/public-api / onMediaQuery
Function: onMediaQuery()
onMediaQuery(
query):Stream<boolean>
Defined in: projects/libraries/streamix/dom/src/lib/streams/onMediaQuery.ts:22
Creates a reactive stream that emits true or false whenever a CSS media query matches or stops matching.
This stream is useful for reacting to viewport size changes, orientation changes, or other media feature conditions.
Behavior:
- Resolves the media query once on first subscription.
- Emits the initial match state on start.
- Emits on every media query change.
- Starts listening on first subscriber.
- Stops listening when the last subscriber unsubscribes.
- Safe to import and subscribe in SSR (no-op).
- Fully compatible with async iteration.
Parameters
query
MaybePromise<string>
A CSS media query string (or promise).
Returns
Stream<boolean>
A stream emitting match state.