Common: Utils: init useIsSmallWindow
This commit is contained in:
parent
47a9f7a367
commit
e7bb8f05ee
22
packages/common/utils/useIsSmallWindow.tsx
Normal file
22
packages/common/utils/useIsSmallWindow.tsx
Normal 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;
|
||||
};
|
Loading…
Reference in New Issue
Block a user