Skip to content

Commit 40408be

Browse files
committed
add useMobile to screenSizeProvider
1 parent 2165d94 commit 40408be

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

frontend/contexts/ScreenSizeContext.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,17 @@ import { createContext, useContext, useEffect, useState } from "react";
22

33
const ScreenSizeContext = createContext<boolean | null>(null);
44

5-
export const ScreenSizeProvider = ({ children }: { children: React.ReactNode }) => {
5+
export const ScreenSizeProvider = ({
6+
useMobile = false,
7+
children,
8+
}: {
9+
useMobile?: boolean;
10+
children: React.ReactNode;
11+
}) => {
612
const [isPC, setIsPC] = useState<boolean>(() => {
13+
if (useMobile) {
14+
return window.innerWidth < 768;
15+
}
716
if (typeof window !== "undefined") {
817
return window.innerWidth > 768;
918
}
@@ -22,7 +31,7 @@ export const ScreenSizeProvider = ({ children }: { children: React.ReactNode })
2231
let timeoutId: ReturnType<typeof setTimeout>;
2332
const debouncedHandleResize = () => {
2433
clearTimeout(timeoutId);
25-
timeoutId = setTimeout(handleResize, 100);
34+
timeoutId = setTimeout(handleResize, 100);
2635
};
2736

2837
window.addEventListener("resize", debouncedHandleResize);
@@ -47,4 +56,5 @@ export const useScreenSize = () => {
4756
throw new Error("useScreenSize must be used within a ScreenSizeProvider");
4857
}
4958
return context;
50-
};
59+
};
60+

0 commit comments

Comments
 (0)