Common: Utils: init useIsSmallWindow

This commit is contained in:
Viktor Fomin 2023-07-28 01:34:43 +03:00
parent 47a9f7a367
commit e7bb8f05ee

View File

@ -0,0 +1,22 @@
import { useState, useEffect } from "react";
import { isDesktop } from "react-device-detect";
export const useIsSmallWindow = (windowWidth: number): boolean => {
const [isSmallWindow, setIsSmallWindow] = useState(false);
const onCheckView = () => {
if (isDesktop && window.innerWidth < windowWidth) {
setIsSmallWindow(true);
} else {
setIsSmallWindow(false);
}
};
useEffect(() => {
window.addEventListener("resize", onCheckView);
return () => window.removeEventListener("resize", onCheckView);
}, []);
return isSmallWindow;
};