@safe-global/safe-react-hooks
Version:
A collection of React Hooks that facilitates the interaction of React apps with Safe Smart Accounts
20 lines • 882 B
JavaScript
import { useContext } from 'react';
import { SafeContext } from '../SafeContext.js';
import { MissingSafeProviderError } from '../errors/MissingSafeProviderError.js';
/**
* Hook to get the SafeConfig object provided by the nearest `SafeProvider`.
* @param params Parameters to customize the hook behavior.
* @param params.config SafeConfig to use instead of the one provided by `SafeProvider`.
* @returns SafeConfig object provided by `SafeProvider` or the one passed as a parameter.
*/
export function useConfig(params) {
const { config: contextConfig, setConfig } = useContext(SafeContext);
if (params?.config) {
return [params.config, setConfig];
}
if (!contextConfig) {
throw new MissingSafeProviderError('`useConfig` must be used within `SafeProvider`.');
}
return [contextConfig, setConfig];
}
//# sourceMappingURL=useConfig.js.map