Skip to content
Playground

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.

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

MOBILE_MAX_WIDTH is 767.

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>

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.

  • 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.

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 for the complete responsive scale and boundary-testing guidance.