T
TanStack3y ago
correct-apricot

Problem with Error: vue-query hooks can only be used inside setup() function.

I created custom composable to use on page login, but when hit that function i got that error. Is it my mistake or what.
No description
7 Replies
correct-apricot
correct-apricotOP3y ago
BTW, i use nuxt and vue query with this version "nuxt": "^3.7.3", "@tanstack/vue-query": "^4.35.3",
correct-apricot
correct-apricotOP3y ago
this is composable file for useAuth
No description
optimistic-gold
optimistic-gold3y ago
Move useAuth call out of onSubmit handler. In that handler you need to only call mutate.
correct-apricot
correct-apricotOP3y ago
thanks man, it's work!! next question, is it possible to watch "error" from function login @MrMentor
correct-apricot
correct-apricotOP3y ago
like this
No description
correct-apricot
correct-apricotOP3y ago
i think login isn't reactive, because when i watch login.error isn't triggered is it my approach is wrong?
optimistic-gold
optimistic-gold3y ago
Login itself is not. But error prop is a ref, so it should be watchable. I would suggest to pass onError either to useMutation or mutate depending where and what you need to do.

Did you find this page helpful?