diff --git a/packages/medusa-react/src/hooks/admin/uploads/mutations.ts b/packages/medusa-react/src/hooks/admin/uploads/mutations.ts index 32cfd4fa04e18..b5b136684eaac 100644 --- a/packages/medusa-react/src/hooks/admin/uploads/mutations.ts +++ b/packages/medusa-react/src/hooks/admin/uploads/mutations.ts @@ -23,7 +23,7 @@ export const useAdminUploadFile = ( return useMutation((payload: IAdminPostUploadsFileReq) => { return client.admin.uploads.create(payload) - }, buildOptions(queryClient, [], options)) + }, buildOptions(queryClient, undefined, options)) } export const useAdminCreatePresignedDownloadUrl = ( @@ -39,7 +39,7 @@ export const useAdminCreatePresignedDownloadUrl = ( return useMutation( (payload: AdminPostUploadsDownloadUrlReq) => client.admin.uploads.getPresignedDownloadUrl(payload), - buildOptions(queryClient, [], options) + buildOptions(queryClient, undefined, options) ) } @@ -55,6 +55,6 @@ export const useAdminDeleteFile = ( return useMutation( (payload: AdminDeleteUploadsReq) => client.admin.uploads.delete(payload), - buildOptions(queryClient, [], options) + buildOptions(queryClient, undefined, options) ) } diff --git a/packages/medusa-react/src/hooks/utils/buildOptions.ts b/packages/medusa-react/src/hooks/utils/buildOptions.ts index 0c8c9435e87a2..145ff13ff90d8 100644 --- a/packages/medusa-react/src/hooks/utils/buildOptions.ts +++ b/packages/medusa-react/src/hooks/utils/buildOptions.ts @@ -8,7 +8,7 @@ export const buildOptions = < TKey extends Array >( queryClient: QueryClient, - queryKey: TKey[] | TKey, + queryKey?: TKey[] | TKey, options?: UseMutationOptions ): UseMutationOptions => { return { @@ -18,10 +18,12 @@ export const buildOptions = < return options.onSuccess(...args) } - if (queryKey.filter(Array.isArray).length > 0) { - queryKey.forEach(key => queryClient.invalidateQueries(key)) - } else { - queryClient.invalidateQueries(queryKey) + if (queryKey !== undefined) { + if (queryKey.filter(Array.isArray).length > 0) { + queryKey.forEach(key => queryClient.invalidateQueries(key)) + } else { + queryClient.invalidateQueries(queryKey) + } } }, }