G$Row
G$Row
TtRPC
Created by G$Row on 5/3/2024 in #❓-help
How to get data type from onMutate function in useMutation
I'm doing optimistic updates using the technique which is documented here https://tanstack.com/query/latest/docs/framework/react/guides/optimistic-updates . I found that I'm using the same queries in multiple spots and want to extract the update code so that I don't have to copy and paste. I can't figure out the type of the data parameter in the onMutate function.
api.task.createTask.useMutation({
onMutate: async (data) => {}})
api.task.createTask.useMutation({
onMutate: async (data) => {}})
I've tried using type MutateData = Parameters<typeof api.task.createTask.useMutation>[0] . The problem is that I can't then access the ['onMutate'] because it doesn't exist on there. Does anyone know how to get this?
30 replies