This repository has been archived on 2024-10-29. You can view files and clone it, but cannot push or open issues or pull requests.
scoresaber-reloadedv3/projects/website/src/hooks/use-is-mobile.ts
2024-10-08 15:32:02 +01:00

21 lines
472 B
TypeScript

import { useEffect, useState } from "react";
export function useIsMobile() {
const checkMobile = () => {
return window.innerWidth < 768;
};
const [isMobile, setIsMobile] = useState(checkMobile());
useEffect(() => {
const handleResize = () => {
setIsMobile(checkMobile());
};
window.addEventListener("resize", handleResize);
return () => {
window.removeEventListener("resize", handleResize);
};
}, []);
return isMobile;
}