mirror of
https://github.com/Yidadaa/ChatGPT-Next-Web.git
synced 2025-08-08 21:44:59 +08:00
feat: reactive isMobileScreen
This commit is contained in:
18
app/utils.ts
18
app/utils.ts
@@ -1,4 +1,5 @@
|
||||
import { EmojiStyle } from "emoji-picker-react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { showToast } from "./components/ui-lib";
|
||||
import Locale from "./locales";
|
||||
|
||||
@@ -47,6 +48,23 @@ export function isIOS() {
|
||||
return /iphone|ipad|ipod/.test(userAgent);
|
||||
}
|
||||
|
||||
export function useMobileScreen() {
|
||||
const [isMobileScreen_, setIsMobileScreen] = useState(false);
|
||||
useEffect(() => {
|
||||
const onResize = () => {
|
||||
setIsMobileScreen(isMobileScreen());
|
||||
};
|
||||
|
||||
window.addEventListener("resize", onResize);
|
||||
|
||||
return () => {
|
||||
window.removeEventListener("resize", onResize);
|
||||
};
|
||||
}, []);
|
||||
|
||||
return isMobileScreen_;
|
||||
}
|
||||
|
||||
export function isMobileScreen() {
|
||||
return window.innerWidth <= 600;
|
||||
}
|
||||
|
Reference in New Issue
Block a user