import { createContext, useContext, ReactNode } from 'react';
import type { PrivacyBoost } from '@sunnyside-io/privacy-boost-wasm';
interface SDKContextValue {
sdk: PrivacyBoost | null;
loading: boolean;
error: Error | null;
}
const SDKContext = createContext<SDKContextValue>({
sdk: null,
loading: true,
error: null,
});
export function PrivacyBoostProvider({
config,
children,
}: {
config: WasmConfig;
children: ReactNode;
}) {
const { sdk, loading, error } = usePrivacyBoost(config);
return (
<SDKContext.Provider value={{ sdk, loading, error }}>
{children}
</SDKContext.Provider>
);
}
export function useSDK() {
const context = useContext(SDKContext);
if (!context.sdk && !context.loading) {
throw new Error('SDK not initialized');
}
return context;
}