Hooks
use-mobile
1/27/2026, 1:17:38 PM modified by MarvinA hook to check if the user is on a mobile device.
use-mobile
A hook to check if the user is on a mobile device.
Install
Preview
TODO
import React from 'react';const MOBILE_BREAKPOINT = 768;export function useIsMobile() { const [isMobile, setIsMobile] = React.useState<boolean | undefined>(undefined); React.useEffect(() => { const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`); const onChange = () => { setIsMobile(window.innerWidth < MOBILE_BREAKPOINT); }; mql.addEventListener('change', onChange); setIsMobile(window.innerWidth < MOBILE_BREAKPOINT); return () => mql.removeEventListener('change', onChange); }, []); return !!isMobile;}Git Commit History(1 commits)
fix: dep
Marvin
1月27日 13:17
b6e70fbd