Skip to Content
BBRICKSv0.7.4
DataInterface hooks

useViewportTier

Follows a resize; read on the first render so a phone never flashes the sidebar. initial is the first value when given (a forced tier), and the server's value: with no window (SSR) the tier is initial, else 'desktop', until the first effect reads the width.

import { useViewportTier } from '@ergasti/bricks';

Examples

Viewport tier

useViewportTier is desktop above 1024px, tablet from 860 to 1024 and mobile below; useIsMobile is the last one as a boolean. They follow the window, so resize it to see them change.

Code
import { useIsMobile, useViewportTier } from '@ergasti/bricks';

function Tier() {
  const tier = useViewportTier();
  const mobile = useIsMobile();
  return <p>Tier: <b>{tier}</b> · mobile: <b>{String(mobile)}</b></p>;
}

Signature

function useViewportTier(initial?: ViewportTier | undefined): ViewportTier

Parameters

Prop

Type

Returns

ViewportTier

useIsMobile · useDebouncedValue · useFocusTrap · useModalLock

Source

src/hooks/useIsMobile.ts (line 16) on GitHub.

On this page