Add Frontend Code
This commit is contained in:
1 parent
c46545f329
commit
e85703df8f
134 files changed
+76840
No files matched your search
@@ -0,0 +1,31 @@
|
||||
"use client";
|
||||
|
||||
import type { ReactNode } from "react";
|
||||
import { createContext, useState } from "react";
|
||||
import { useEffect } from "react";
|
||||
|
||||
export const ResponsiveContext = createContext<boolean | undefined>(undefined);
|
||||
|
||||
export default function ResponsiveProvider({
|
||||
children,
|
||||
}: {
|
||||
children: ReactNode;
|
||||
}) {
|
||||
const [isMobile, setIsMobile] = useState<boolean | undefined>(undefined);
|
||||
|
||||
useEffect(() => {
|
||||
if (typeof window === "undefined") return;
|
||||
const handleResize = () => setIsMobile(window.innerWidth < 640);
|
||||
|
||||
handleResize();
|
||||
window.addEventListener("resize", handleResize);
|
||||
|
||||
return () => window.removeEventListener("resize", handleResize);
|
||||
}, [setIsMobile]);
|
||||
|
||||
return (
|
||||
<ResponsiveContext.Provider value={isMobile}>
|
||||
{children}
|
||||
</ResponsiveContext.Provider>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user