createMediaQuery
Create a reactive boolean accessor tracking the match status of any CSS media query.
createMediaQuery returns a reactive boolean accessor that tracks whether a CSS media query matches. It updates when the query’s match state changes.
Import#
Signature#
Usage Example#
src/ResponsiveLayout.tsx
Features#
- Returns
defaultValueduring server rendering and until the first client effect runs, so server and hydrated markup match. It then reads the real match state and subscribes to changes withmatchMedia. - The
queryargument may be an accessor, so the tracked query can change reactively (for example,() => isDesktop() ? '(min-width: 1024px)' : '(min-width: 640px)'). - Accepts a query with a leading
@media; the prefix is stripped. - Removes the media listener when the Solid owner disposes or the query changes.
- Stays at
defaultValuewhenwindow.matchMediais unavailable.