MediaQuery class creates a reactive media query that automatically updates when the viewport matches or stops matching the query.
Import
Usage
Responsive design
Multiple breakpoints
Conditional features
Properties
Whether the media query currently matches. This property is reactive.
The media query string used to create this instance
Constructor
A media query string (e.g., ‘(min-width: 768px)‘)
Notes
- Automatically adds and removes event listeners
- Updates reactively when the match state changes
- More efficient than using window.matchMedia directly
- Works server-side (always returns false for matches)
- Cleanup is handled automatically when component is destroyed