# MediaQueryProvider **📖 Live documentation:** https://cds.coinbase.com/components/other/MediaQueryProvider/ Manages window.matchMedia subscriptions with SSR support. ## Import ```tsx import { MediaQueryProvider } from '@coinbase/cds-web/system/MediaQueryProvider' ``` ## Examples ### MediaQueryProvider component The MediaQueryProvider manages `window.matchMedia` subscriptions with SSR support. Provides a single state shared by all subscriptions to ensure Suspense works correctly. Use the `defaultValues` prop to configure SSR defaults, and the `useMediaQuery` hook to subscribe to `window.matchMedia` changes. [See the `useMediaQuery` docs here →](/hooks/useMediaQuery) ### Basic usage Use the `useMediaQuery` hook to call `window.matchMedia` with SSR support. It must be used within a MediaQueryProvider component. This hook is ideal for conditional rendering based on viewport size, user preferences, or other media features. It subscribes to a single state shared by all media queries to ensure Suspense works correctly. [See the `useMediaQuery` docs here →](/hooks/useMediaQuery) :::warning Do not use `useMediaQuery` for responsive styles. Use CSS media queries or [the `StyleProps` API](/getting-started/styling#responsive-styles) for responsive styles. ::: ```tsx live () => { const Page = () => { const isMobile = useMediaQuery('(max-width: 767px)'); const prefersDarkMode = useMediaQuery('(prefers-color-scheme: dark)'); return (
{JSON.stringify({ isMobile, prefersDarkMode }, null, 2)}
);
};
const App = () => (
{JSON.stringify({ isPortrait, isHighDPI, isTouch, isMediumHeight, complexQuery }, null, 2)}
);
};
```
## Props
| Prop | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `defaultValues` | `MediaSettings` | No | `{ width: breakpoints.desktop, colorScheme: 'light' as const, }` | - |