Skip to main content

Overview

The useIsMobile hook detects if the current viewport width is below the mobile breakpoint (768px).

Import

import { useIsMobile } from 'sunpeak';

Signature

function useIsMobile(): boolean

Returns

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

Usage

import { useIsMobile } from 'sunpeak';

function MyWidget() {
  const isMobile = useIsMobile();

  return (
    <div className={isMobile ? 'mobile-layout' : 'desktop-layout'}>
      {isMobile ? 'Mobile view' : 'Desktop view'}
    </div>
  );
}