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/src/hooks/use-is-mobile.ts

21 lines
473 B
TypeScript
Raw Normal View History

2024-09-30 06:20:58 +00:00
import { useEffect, useState } from "react";
2024-09-28 14:19:51 +00:00
export function useIsMobile() {
const checkMobile = () => {
return window.innerWidth < 1536;
};
const [isMobile, setIsMobile] = useState(checkMobile());
2024-09-28 14:19:51 +00:00
useEffect(() => {
const handleResize = () => {
setIsMobile(checkMobile());
2024-09-28 14:19:51 +00:00
};
window.addEventListener("resize", handleResize);
return () => {
window.removeEventListener("resize", handleResize);
};
2024-09-28 14:19:51 +00:00
}, []);
return isMobile;
}