Skip to main content

Function: useIsMobile()

@arolariu/components


@arolariu/components / useIsMobile

Function: useIsMobile()

useIsMobile(): boolean

Defined in: hooks/useIsMobile.tsx:19

A custom React hook that detects whether the current device is a mobile device based on the screen width (viewport < 768px).

Returns

boolean

true if the viewport width is less than 768px, false otherwise.

Example

function MyComponent() {
const isMobile = useIsMobile();
return <div>{isMobile ? 'Mobile View' : 'Desktop View'}</div>;
}
// was this page useful?