A React hook that detects whether the current viewport width is below a specified breakpoint

const MyComponent = () => {
const isMobile = useIsMobile(768);

return (
<div>
{isMobile ? 'Mobile View' : 'Desktop View'}
</div>
);
}
  • Parameters

    • breakpoint: number = 768

      The width threshold in pixels to determine mobile view (default: 768px)

    Returns boolean

    boolean - True if the viewport width is less than the breakpoint