a11oy / web /src /context /OrgContext.tsx
betterwithage's picture
sync(space): complete build context — fix BUILD_ERROR (CTO)
518343a verified
Raw
History Blame Contribute Delete
745 Bytes
import { createContext, useContext, useState } from 'react';
import type { ReactNode } from 'react';
export type OrgId = 'szl' | 'acme' | 'northwind';
interface OrgContextType {
currentOrg: OrgId;
setOrg: (org: OrgId) => void;
}
const OrgContext = createContext<OrgContextType | undefined>(undefined);
export function OrgProvider({ children }: { children: ReactNode }) {
const [currentOrg, setOrg] = useState<OrgId>('szl');
return (
<OrgContext.Provider value={{ currentOrg, setOrg }}>
{children}
</OrgContext.Provider>
);
}
export function useOrg() {
const context = useContext(OrgContext);
if (context === undefined) {
throw new Error('useOrg must be used within an OrgProvider');
}
return context;
}