Listen for media-query changes with the standard browser event API.
A missing media query or unavailable standard event methods return an inert cleanup function.
Usage:
import { listenMediaQueryChanges } from "mazey";const media = window.matchMedia("(prefers-color-scheme: dark)");const stop = listenMediaQueryChanges(media, event => { console.log(event.matches);});stop();stop(); Copy
import { listenMediaQueryChanges } from "mazey";const media = window.matchMedia("(prefers-color-scheme: dark)");const stop = listenMediaQueryChanges(media, event => { console.log(event.matches);});stop();stop();
Media-query result to observe, or null when unavailable.
null
Callback invoked for media-query change events.
An idempotent function that removes the registered listener.
If listener is not a function or media is neither an object nor null.
listener
media
This helper does not call matchMedia, invoke the listener immediately, or modify the DOM. It is safe during SSR when null is supplied.
matchMedia
Listen for media-query changes with the standard browser event API.
A missing media query or unavailable standard event methods return an inert cleanup function.
Usage: