feat: add mobile layout detection

This commit is contained in:
cita
2026-03-10 14:39:57 +08:00
parent dbf828467b
commit 4e3d82aae1
3 changed files with 34 additions and 0 deletions
+16
View File
@@ -0,0 +1,16 @@
import { useEffect, useState } from 'react';
export function useIsMobile(breakpoint = 768) {
const [isMobile, setIsMobile] = useState(() => (
typeof window !== 'undefined' ? window.innerWidth < breakpoint : false
));
useEffect(() => {
const update = () => setIsMobile(window.innerWidth < breakpoint);
update();
window.addEventListener('resize', update);
return () => window.removeEventListener('resize', update);
}, [breakpoint]);
return isMobile;
}