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
Section titled “Import”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:
"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:
<Stack direction={{ base: "column", md: "row" }} gap="4"> {children}</Stack>Custom maximum width
Section titled “Custom maximum width”Pass a pixel maximum when a behavior has a product-specific boundary:
const useCompactNavigation = useMobileMode(899);The comparison is inclusive, so this value returns true through 899px and false from 900px.
Behavior
Section titled “Behavior”- Reads
window.visualViewport.widthwhen available, otherwisewindow.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
Section titled “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 for the complete responsive scale and boundary-testing guidance.