diff --git a/src/runtime/client.ts b/src/runtime/client.ts index 176df2e..6d6f5ec 100644 --- a/src/runtime/client.ts +++ b/src/runtime/client.ts @@ -31,6 +31,18 @@ export type TError = TRPCClientErrorLike export type TQueryValues = inferProcedures + + +/** + * Calculates the key used for `useAsyncData` call + * @param pathAndInput + */ +export function getQueryKey< + TPath extends keyof TQueryValues & string + >(pathAndInput: [path: TPath, ...args: inferHandlerInput]) { + return `${pathAndInput[0]}-${objectHash(pathAndInput[1] ? JSON.stringify(pathAndInput[1]) : '')}` +} + export async function useAsyncQuery< TPath extends keyof TQueryValues & string, TOutput extends TQueryValues[TPath]['output'] = TQueryValues[TPath]['output'], @@ -41,7 +53,7 @@ export async function useAsyncQuery< options: AsyncDataOptions = {}, ): Promise, PickKeys>, TError>> { const { $client } = useNuxtApp() - const key = `${pathAndInput[0]}-${objectHash(pathAndInput[1] ? JSON.stringify(pathAndInput[1]) : '')}` + const key = getQueryKey(pathAndInput) const serverError = useState(`error-${key}`, () => null) const { error, data, ...rest } = await useAsyncData( key,