useMediaQuery
Subscribe and respond to changes to CSS media queries.
Installation
npm i @raddix/use-media-query
Usage
Basic example
In this example we will show a message if the screen size is less than 768px.
Using a number as a query
You can also pass a number as a query, in this case it will match the media query (min-width: ${number}px).
API
Parameters
| Name | Description | Required | Type |
|---|---|---|---|
| query | The media query to match. It can be any valid media query, like `(max-width: 768px)` or a number. | Yes | string | number |
Return value
Returns true if the media query matches and false if it does not.