ilokesto

Media

Media renders children based on a CSS media query match. With a render prop it receives the matches boolean; otherwise it renders children when the query matches and fallback when it does not.

import { Media } from '@ilokesto/utilinent';

<Media query="(min-width: 768px)">{(matches) => matches ? <Desktop /> : <Mobile />}</Media>

<Media query="(min-width: 768px)" fallback={<MobileNav />}><DesktopNav /></Media>

Props

PropTypeDescription
querystringA CSS media query string.
childrenReactNode | (matches) => ReactNodeContent or render prop.
fallbackReactNodeRendered when the query does not match (non-render-prop usage). Defaults to null.

SSR

During server rendering and the client's first hydration render, Media renders the non-matching branch: fallback for non-render-prop usage, or the render-prop result for false. It switches to the matching branch synchronously before the first paint, so server and client markup hydrate without mismatches even when the media states differ.

On this page