Type is not assignable to type mutate function
Hello all, I get this error
and I am unsure how to fix it. I followed the same pattern as my createDummy function, both of which write react query functions to make mutation calls to the database.

14 Replies
sensitive-blue•15mo ago
mutationFn
only provides one parameter. You'll need to combine dummyId
and dummy
under one objectsensitive-blue•15mo ago
Mastering Mutations in React Query
Learn all about the concept of performing side effects on the server with React Query.
sensitive-blue•15mo ago
If your
updateDummy
method must be that way, you could do:
And invoke via something like:
rising-crimsonOP•15mo ago
Thank you @troywoy for your reply
Should I be spreading the contents of the dummy object?
sensitive-blue•15mo ago
Depends on how you call
mutate
rising-crimsonOP•15mo ago
I'd like to keep the params for the createDummy api call unchanged:
When I implement this code change:
sensitive-blue•15mo ago
And how do you call mutate from
useUpdateDummyMutation
?rising-crimsonOP•15mo ago
I get new TS error properties don't exist on type 'void'
sensitive-blue•15mo ago
You need to type the
({ dummyId, dummy }) =>
portionsensitive-blue•15mo ago
TS Playground - An online editor for exploring TypeScript and JavaS...
The Playground lets you write TypeScript or JavaScript online in a safe and sharable way.
sensitive-blue•15mo ago
That's a sloppy example
rising-crimsonOP•15mo ago
I call useMutate as part of a long form submission, here's the relevant part:
sensitive-blue•15mo ago
You have two options there.
Either spread
...dummy
on the mutateAsync
line:
Or put dummyId
onto the const dummy
object and simply use that:
rising-crimsonOP•15mo ago
@troywoy thank you very much. You have helped immensely.