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 the current viewport or system setting. It updates automatically when the screen resizes or system settings change.
Import#
Signature#
Usage Example#
src/ResponsiveLayout.tsx
Features#
- SSR Safe: Uses
defaultValueduring server rendering and attachesmatchMedialisteners in the browser. - Dynamic Queries: The
queryargument can be a reactive accessor function (e.g.() => isDesktop() ? '(min-width: 1024px)' : '(min-width: 640px)'). - Auto Cleanup: Disposes of the underlying media listener when the Solid owner scope disposes.