quivr/frontend/lib/hooks/useDevice.ts
Mamadou DICKO dc64470d5d
Ux improvment (#382)
* feat: make chat list hidden on mobile by default

* feat: autoclose chat list on click

* feat: move footer to chat lists bottom when user is logged in

* feat: fix header when user is logged in

* chore: refacto ChatMessages

* feat: reverse chat list display on fetch

* feat: fix new chat button
2023-06-27 11:28:09 +02:00

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 };
};