anmot.
anmot.5mo ago

convexAction in @convex-dev/react-query ?

How can we invoke convex actions using @convex-dev/react-query? PS: loving convex-dev/react-query so far. Great work!
6 Replies
erquhart
erquhart5mo ago
It looks like there's a useConvexAction export, I'd expect it to be used the same as a mutation, which doesn't behave any differently with react query than a standard mutation.
const { mutate } = useMutation({
mutationFn: useConvexAction(api.my.func),
})
const { mutate } = useMutation({
mutationFn: useConvexAction(api.my.func),
})
Someone may correct me in the morning lol, this is just what I gather looking at the code.
anmot.
anmot.OP5mo ago
Thanks for looking into this. This is seems to work. If someone can confirm if this is the recommended approach, that would be great. It might be worth mentioning in the docs as well. https://docs.convex.dev/client/tanstack-query
Convex with TanStack Query | Convex Developer Hub
If you already use TanStack Query the query
erquhart
erquhart5mo ago
@ballingt can you give a 👍 / 👎 on this (whether this is actually the intended approach, that is)
ballingt
ballingt5mo ago
Yes exactly! And you can also use a convex action with useQuery with convexAction.
ballingt
ballingt5mo ago
thanks, I'll add docs for this! It's mentioned in the readme https://github.com/get-convex/convex-react-query?tab=readme-ov-file#mutations-and-actions but I need to port it over.
GitHub
GitHub - get-convex/convex-react-query
Contribute to get-convex/convex-react-query development by creating an account on GitHub.
anmot.
anmot.OP5mo ago
Great. Thanks for the confirmation.

Did you find this page helpful?