This repository has been archived on 2026-07-15. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
drive/frontend/src/hooks/useIsMobile.ts
Elijah 1f83d57942
All checks were successful
Automated Container Build / build-and-push (push) Successful in 3m25s
fix(frontend): update Share interface property from download_count to downloads
2026-05-26 14:54:50 -07:00

21 lines
638 B
TypeScript

import { useState, useEffect } from 'react';
const MOBILE_BREAKPOINT = 768;
export function useIsMobile(breakpoint = 768) {
const [isMobile, setIsMobile] = useState<boolean>(false);
const [hasMounted, setHasMounted] = useState(false);
useEffect(() => {
setHasMounted(true);
const mql = window.matchMedia(`(max-width: ${breakpoint}px)`);
setIsMobile(mql.matches);
const handler = (e: MediaQueryListEvent) => setIsMobile(e.matches);
mql.addEventListener('change', handler);
return () => mql.removeEventListener('change', handler);
}, [breakpoint]);
if (!hasMounted) return false;
return isMobile;
}