Convex mutation inside tanstack/react query mutation
I want to do crazy browser push api stuff.
For this I want to abstract a function inside a tanstack query mutation
this tanstack mutation has to call the convex mutation. (it has to make a db write and a bunch of extra stuff)
Is that possible with the convex mutation?
13 Replies
Neither Tanstack Query or Convex care what you do with the result of a mutation, so it should work just fine.
but I to define to convex mutation inside the tanstack mutation ig
so it's not just about the results it's about the defintion
You mean calling
useMutation()
?
The definition is backend so I'm guessing you're not referring to thatMhmm, maybe I break it down to that:
(obvs the hooks need to be inside of a hook or component)
ok, so I wrap the two hooks inside a hook
sounds reasonable
thank you
For sure
❤️ You're the best
so tried it. It's not working, but I think it's just the complexity of the functionality that I want to implement. If I have problems with the setup I will write it here.
If you can share any code (and the expected vs actual behavior), happy to take a look
Tiny bit simpler:
Never used useConvex. Does it has any other benifits besides that it is simpler?
it just gives you a lower-level handle to the ConvexReactClient
convex/react
's useMutation
gives you a memoized callback and optimistic updates, neither of which are needed in this example given you're using useMutation
from tanstack/query
.