Skip to main content

useBreakpoints

useBreakpoints is a hook that resolves a value for the viewport, such as a result limit or a control size.

Import

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

Other links

Columns for this viewport: 1
"use client";

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

export const BreakpointValue = () => {
  const columns = useBreakpoints({ xs: 1, sm: 2, lg: 3 });

  return <Text>Columns for this viewport: {columns}</Text>;
};

Features

  • Resolves a scalar or breakpoint map to one value.
  • Inherits the nearest defined smaller breakpoint.
  • Updates when viewport media queries change.
  • Uses the provider’s initial breakpoint for server rendering.

Include xs as the base value. Use this hook when JavaScript needs the resolved value; prefer responsive component props for styling.

Breakpoint Inheritance

For { xs: 1, sm: 2, lg: 3 }, missing breakpoints inherit the nearest smaller value:

BreakpointValue
xs1
sm2
md2
lg3
xl3

Without xs, an object passes through unchanged instead of resolving a breakpoint.

Typed Values

Supply a generic type when the result must match another API’s allowed values.

Resolved size: sm
"use client";

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

export const ResponsiveButton = () => {
  const size = useBreakpoints<"sm" | "md">({ xs: "sm", md: "md" });

  return (
    <Stack gap={3} align="start">
      <Button size={size}>Create project</Button>
      <Text size="body-sm-desktop" color="subtle">
        Resolved size: {size}
      </Text>
    </Stack>
  );
};

A scalar passes through unchanged:

const limit = useBreakpoints(10); // 10 at every breakpoint

Initial Breakpoint

Use VortexProvider to set the initial breakpoint (xs by default). The hook resolves the viewport after hydration.

"use client";

import type { ReactNode } from "react";
import { VortexProvider } from "@vortexlabs/vortex";

type Props = { children: ReactNode };

export const AppProvider = (props: Props) => {
  const { children } = props;

  return <VortexProvider defaultBreakpoint="md">{children}</VortexProvider>;
};

Breakpoint widths come from the theme’s runtime variables, with library defaults as a fallback.