mirror of
https://github.com/streamich/react-use.git
synced 2026-01-18 14:06:52 +00:00
28 lines
462 B
Markdown
28 lines
462 B
Markdown
# `useMedia`
|
|
|
|
React sensor hook that tracks state of a CSS media query.
|
|
|
|
## Usage
|
|
|
|
```jsx
|
|
import {useMedia} from 'react-use';
|
|
|
|
const Demo = () => {
|
|
const isWide = useMedia('(min-width: 480px)');
|
|
|
|
return (
|
|
<div>
|
|
Screen is wide: {isWide ? 'Yes' : 'No'}
|
|
</div>
|
|
);
|
|
};
|
|
```
|
|
|
|
## Reference
|
|
|
|
```ts
|
|
useMedia(query: string, defaultState: boolean = false): boolean;
|
|
```
|
|
|
|
The `defaultState` parameter is only used as a fallback for server side rendering.
|