src/hooks/useMobile.tsx
import { useState, useEffect } from "react";
export function useMobile(): boolean {
const [isMobile, setIsMobile] = useState<boolean>(false);
useEffect(() => {
const checkIfMobile = (): void => {
setIsMobile(window.innerWidth < 640);
};
checkIfMobile();
window.addEventListener("resize", checkIfMobile);
return () => window.removeEventListener("resize", checkIfMobile);
}, []);
return isMobile;
}