T
TanStack2y ago
rare-sapphire

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
rare-sapphire
rare-sapphireOP2y ago
BTW, i use nuxt and vue query with this version "nuxt": "^3.7.3", "@tanstack/vue-query": "^4.35.3",
rare-sapphire
rare-sapphireOP2y ago
this is composable file for useAuth
No description
sensitive-blue
sensitive-blue2y ago
Move useAuth call out of onSubmit handler. In that handler you need to only call mutate.
rare-sapphire
rare-sapphireOP2y ago
thanks man, it's work!! next question, is it possible to watch "error" from function login @MrMentor
rare-sapphire
rare-sapphireOP2y ago
like this
No description
rare-sapphire
rare-sapphireOP2y ago
i think login isn't reactive, because when i watch login.error isn't triggered is it my approach is wrong?
sensitive-blue
sensitive-blue2y 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?