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.

7 Replies
correct-apricotOP•3y ago
BTW, i use nuxt and vue query with this version
"nuxt": "^3.7.3",
"@tanstack/vue-query": "^4.35.3",
correct-apricotOP•3y ago
this is composable file for useAuth

optimistic-gold•3y ago
Move
useAuth call out of onSubmit handler. In that handler you need to only call mutate.correct-apricotOP•3y ago
thanks man, it's work!!
next question, is it possible to watch "error" from function login @MrMentor
correct-apricotOP•3y ago
like this

correct-apricotOP•3y ago
i think
login isn't reactive, because when i watch login.error isn't triggered
is it my approach is wrong?optimistic-gold•3y 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.