quivr/frontend/lib/hooks/useDevice.ts

26 lines
607 B
TypeScript
Raw Normal View History

import { useEffect, useState } from "react";
export const useDevice = (): { isMobile: boolean } => {
const [isMobile, setIsMobile] = useState(false);
useEffect(() => {
const handleResize = () => {
const screenWidth = window.innerWidth;
setIsMobile(screenWidth < 576);
};
// Initial check
handleResize();
// Event listener for screen resize
window.addEventListener("resize", handleResize);
// Clean up event listener on component unmount
return () => {
window.removeEventListener("resize", handleResize);
};
}, []);
return { isMobile };
};