frontend client for gemstone. decentralised workplace app
1import { isDevMode } from "@/lib/utils/env";
2import type { Dispatch, ReactNode, SetStateAction } from "react";
3import { createContext, useContext, useState } from "react";
4
5interface DebugContextValue {
6 showStackHeader: boolean;
7 setShowStackHeader: Dispatch<SetStateAction<boolean>>;
8}
9
10const DebugContext = createContext<DebugContextValue | null>(null);
11
12export const useDebugState = () => {
13 const value = useContext(DebugContext);
14 if (!value)
15 throw new Error(
16 "Debug provider failed to initialise. Did you access this out of tree somehow? Tried to access debug value before it was initialised.",
17 );
18 return value;
19};
20
21export const DebugProvider = ({ children }: { children: ReactNode }) => {
22 const [showStackHeader, setShowStackHeader] = useState(false);
23
24 const value: DebugContextValue = {
25 showStackHeader,
26 setShowStackHeader,
27 };
28 return <DebugContext value={value}>{children}</DebugContext>;
29};