mirror of
https://github.com/StanGirard/quivr.git
synced 2024-12-27 13:22:44 +03:00
26 lines
607 B
TypeScript
26 lines
607 B
TypeScript
|
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 };
|
||
|
};
|