// Utilities
useIsMobile
Hook that tracks whether the viewport is below the mobile breakpoint.
// Rendering preview…
// Install
npx shadcn@latest add @dakik/use-is-mobile// Usage
1import { useIsMobile } from "@/hooks/use-is-mobile";// Code
1import React from "react";23const MOBILE_BREAKPOINT = 768;45export const useIsMobile = () => {6 const [isMobile, setIsMobile] = React.useState<boolean | undefined>(7 undefined8 );910 React.useEffect(() => {11 const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`);1213 const onChange = () => {14 setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);15 };1617 mql.addEventListener("change", onChange);1819 setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);2021 return () => mql.removeEventListener("change", onChange);22 }, []);2324 return !!isMobile;25};26