matchMedia
A browser function that checks whether the page currently matches a CSS media query, such as a dark colour scheme or a narrow screen, and reports changes.
In more detail
It returns an object whose matches property is the current answer and which fires a change event. It lets scripts follow the same breakpoints as the CSS.
Example
In React, subscribe to it with useSyncExternalStore rather than copying it into state.Related terms
- useSyncExternalStore — The React hook for reading data from a store outside React, such as a state library or a browser API, without tearing.
- CSS — The language that describes how web pages look: colours, fonts, spacing, layout and animation.
Taught in
- useSyncExternalStore: Tearing-Free Store Subscriptions — React 19 & Modern Component Architecture