lab.waku.org/examples/keystore-management/src/contexts/rln/RLNImplementationContext.tsx
2025-03-27 15:38:43 +05:30

30 lines
984 B
TypeScript

"use client";
import { createContext, useContext, useState, ReactNode } from 'react';
export type RLNImplementationType = 'standard' | 'light';
interface RLNImplementationContextType {
implementation: RLNImplementationType;
setImplementation: (implementation: RLNImplementationType) => void;
}
const RLNImplementationContext = createContext<RLNImplementationContextType | undefined>(undefined);
export function RLNImplementationProvider({ children }: { children: ReactNode }) {
const [implementation, setImplementation] = useState<RLNImplementationType>('light');
return (
<RLNImplementationContext.Provider value={{ implementation, setImplementation }}>
{children}
</RLNImplementationContext.Provider>
);
}
export function useRLNImplementation() {
const context = useContext(RLNImplementationContext);
if (context === undefined) {
throw new Error('useRLNImplementation must be used within a RLNImplementationProvider');
}
return context;
}