# useMediaQuery

## Specification

Returns a boolean verdict whether device matches the given media query Object.

## Definition

```typescript
type UseMediaQuery = (breakpoint: Breakpoint, initialMatches?: boolean) => boolean
```

Please see the Breakpoints page for the `Breakpoint` type reference:

{% content-ref url="../../fundamentals/breakpoints" %}
[breakpoints](https://redd.gitbook.io/atomic-layout/fundamentals/breakpoints)
{% endcontent-ref %}

## Example

```jsx
import React from 'react'
import { useMediaQuery } from 'atomic-layout'

export const Component = () => {
  const isSmallScreen = useMediaQuery({ maxWidth: 450 })
  
  return isSmallScreen ? <p>On mobile</p> : <p>On larger screens</p>
}
```

### Using initial match

The hook resolves to `false` upon initial render. To change that behavior pass the initial value as the second argument to the hook:

```jsx
import React from 'react'
import { useMediaQuery } from 'atomic-layout'

export const Component = () => {
  const isPortrait = useMediaQuery({ orientation: 'portrait' }, true)
  
  return <AnotherComponent isPortrait={isPortrait} />
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://redd.gitbook.io/atomic-layout/api/hooks/use-media-query.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
