tmy03
tmy0311mo ago

TypeError: queryClient.getMutationDefaults is not a function (it is undefined)

Hi! There's not much code to show here, as I'm really not sure where the error actually occurs. In my React component I have: const { mutate } = api.story.create.useMutation(); This gives the following error: ERROR TypeError: queryClient.getMutationDefaults is not a function (it is undefined) Has anyone experienced the same? I can't find any good results on Google, so I guess it's not a typical issue. The is the first mutation I've tried to do. GET queries are working just fine.
1 Reply
tmy03
tmy0311mo ago
The error happens in here trpc/packages/react-query/src/shared/hooks/createHooksInternal.tsx, line 347 on queryClient.getMutationDefaults:
function useMutation(
// FIXME: this should only be a tuple path in next major
path: string | [string],
opts?: UseTRPCMutationOptions<unknown, TError, unknown, unknown>,
): UseTRPCMutationResult<unknown, TError, unknown, unknown> {
const { client } = useContext();
const queryClient = useQueryClient({ context: ReactQueryContext });
const actualPath = Array.isArray(path) ? path[0] : path;

const defaultOpts = queryClient.getMutationDefaults([
actualPath.split('.'),
]);
function useMutation(
// FIXME: this should only be a tuple path in next major
path: string | [string],
opts?: UseTRPCMutationOptions<unknown, TError, unknown, unknown>,
): UseTRPCMutationResult<unknown, TError, unknown, unknown> {
const { client } = useContext();
const queryClient = useQueryClient({ context: ReactQueryContext });
const actualPath = Array.isArray(path) ? path[0] : path;

const defaultOpts = queryClient.getMutationDefaults([
actualPath.split('.'),
]);
I'm using tRPC version 10.43.6 Nevermind. I was using a @tanstack/react-query version 5. Downgraded to 4 and everything works.