@safe-global/safe-react-hooks
Version:
A collection of React Hooks that facilitates the interaction of React apps with Safe Smart Accounts
25 lines • 1.15 kB
JavaScript
import { useCallback } from 'react';
import { useQuery } from '@tanstack/react-query';
import { useConfig } from '../hooks/useConfig.js';
import { usePublicClient } from '../hooks/usePublicClient.js';
/**
* Hook for sending a custom query via the SafeClient.
* @param params Parameters to customize the hook behavior.
* @param params.config SafeConfig to use instead of the one provided by `SafeProvider`.
* @param params.querySafeClientFn Function to query the SafeClient.
* @param params.queryKey Key to identify the query.
* @returns Object containing the query result.
*/
export function usePublicClientQuery(params) {
const { querySafeClientFn, queryKey } = params;
const [config] = useConfig({ config: params.config });
const safeClient = usePublicClient({ config: params.config });
const queryFn = useCallback(() => {
if (!safeClient) {
throw new Error('SafeClient not initialized');
}
return querySafeClientFn(safeClient);
}, [safeClient, querySafeClientFn]);
return useQuery({ queryKey: [...queryKey, config], queryFn });
}
//# sourceMappingURL=usePublicClientQuery.js.map