コンテンツにスキップ
Vantage
English
Esc
navigateopen⌘Jpreview

useIsMobile()

A hook that reports whether the viewport is narrow.

Returns whether the viewport is narrow (under 768px). It is the same check Sidebar uses to switch to a sheet on mobile.

import { useIsMobile } from "@squadbase/vantage/ui";

export default function Overview() {
  const isMobile = useIsMobile();
  return <EChart option={option} height={isMobile ? 200 : 360} />;
}

It subscribes to matchMedia, so resizing re-renders. Note that the first render starts at false — where you can, express layout branches as CSS breakpoints instead.

このページは役に立ちましたか?