Skip to main content

useBreakpoints

useBreakpoints is a hook that resolves a value for the window size, such as a column count or a layout mode.

Import

import { useBreakpoints } from '@vortexlabs/vortex-native';

Other links

import { Stack, Text, useBreakpoints } from "@vortexlabs/vortex-native";

const Example = () => {
  const layout = useBreakpoints({ xs: "Compact", sm: "Medium", md: "Expanded" });

  return (
    <Stack gap={1}>
      <Text color="subtle">Layout</Text>
      <Text size="heading-sm">{layout}</Text>
    </Stack>
  );
};

Features

  • Resolves a scalar or breakpoint map to one value.
  • Inherits the nearest defined smaller breakpoint.
  • Updates on rotation, folding, and split-screen resizing.

Breakpoint Inheritance

A map needs xs as its base value. An omitted breakpoint inherits the nearest smaller value, so here sm uses xs and lg uses md.

const columns = useBreakpoints({ xs: 1, md: 2, xl: 3 });

A scalar passes through unchanged at every breakpoint.

const columns = useBreakpoints(2); // 2

Window Size

Breakpoints follow the window width, using the theme's minimum widths: sm from 600 and md from 840 in the default themes. A window shorter than the theme's compactHeight, such as a phone in landscape, always resolves to xs.