Use Mobile
retab-ui/use-mobileFreeHook
A media query hook for mobile responsive UI.
Install it
npx shadcn@latest add https://ui.retab.com/r/use-mobile.jsonSource
1import * as React from "react";2import { useMountEffect } from "@/hooks/use-mount-effect";34const MOBILE_BREAKPOINT = 768;56export function useIsMobile() {7 const [isMobile, setIsMobile] = React.useState<boolean | undefined>(8 undefined,9 );1011 useMountEffect(() => {12 const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`);13 const onChange = () => {14 setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);15 };16 mql.addEventListener("change", onChange);17 setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);18 return () => mql.removeEventListener("change", onChange);19 });2021 return !!isMobile;22}
What it pulls in
Other registry items
Files it writes
More from retab-ui
All 130 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Use Keyed Layout Effectuse-keyed-layout-effect | retab-ui | Hooks | Free | no deps | |
| Use Keyed Mount Effectuse-keyed-mount-effect | retab-ui | Hooks | Free | no deps | |
| Use Mount Effectuse-mount-effect | retab-ui | Hooks | Free | no deps |
