# useMobileMode

Track whether the visual viewport is within a configurable compact-width range.

`useMobileMode` returns whether the current visual viewport width is at or below a maximum width. Its default threshold ends immediately before the shared `md` breakpoint.

## Import

```tsx
import { MOBILE_MAX_WIDTH, useMobileMode } from "@zentara-co/zenos-ui";
```

`MOBILE_MAX_WIDTH` is `767`.

## Usage

Use the hook when width changes interaction behavior rather than presentation alone:

```tsx
"use client";

import { useMobileMode } from "@zentara-co/zenos-ui";

export function AssetFilters() {
  const isMobile = useMobileMode();

  return isMobile ? <FiltersSheet /> : <FiltersPopover />;
}
```

For ordinary reflow, prefer responsive props or Tailwind utilities:

```tsx
<Stack direction={{ base: "column", md: "row" }} gap="4">
  {children}
</Stack>
```

## Custom maximum width

Pass a pixel maximum when a behavior has a product-specific boundary:

```tsx
const useCompactNavigation = useMobileMode(899);
```

The comparison is inclusive, so this value returns `true` through 899px and `false` from 900px.

## Behavior

- Reads `window.visualViewport.width` when available, otherwise `window.innerWidth`.
- Rounds the viewport width before comparing it with the maximum.
- Subscribes to both window and visual-viewport resize events.
- Re-subscribes when the supplied maximum changes.
- Removes every listener when the component unmounts.

## Server rendering

The hook returns `false` when browser globals are unavailable, then reads the viewport after mounting. The rendered interaction may change on the client at compact widths.

Keep the server version valid, preserve focus when interaction patterns switch, and avoid using the hook to conditionally remove essential content. CSS remains the better choice when both versions differ only in layout or visibility.

See [Breakpoints](/foundations/breakpoints/) for the complete responsive scale and boundary-testing guidance.

Source: https://zenos-ui.pages.dev/hooks/use-mobile-mode/