Skip to content

useIsMobile

True below the md breakpoint (768px).

useIsMobile() is true while the window is narrower than 768px, the width where foundation changes to its phone sizes, and follows the window as it resizes. It is false on the server and on the first render, so the desktop layout is what the HTML carries. Use it when the two layouts are different components, as @khaeli/sidebar does when it becomes a sheet. When only the styling differs, a md: class does the same with no script.

Which layout is active

Window under 768pxNo, desktop layout

Installation

npx shadcn@latest add @khaeli/use-mobile

Installs with

Nothing else. This item needs no other Registry item and no npm package.

Registry JSON

The item as the shadcn CLI reads it, with every file it ships: https://ui.khaeli.com/r/use-mobile.json