using composables outside script setup (eg. Pinia action) #6114
Unanswered
farin
asked this question in
Help/Questions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Official documentation says
Composables should only be called synchronously in <script setup> or the setup() hook. In some cases, you can also call them in lifecycle hooks like onMounted().
What about using them outside?
I don't mean in component, where is script setup.
In my case I mean use them from Pinia actions.
It makes definitely sense to set cookie / call mutation from Pinia action.
Logic from other libraries are often exposed as composable (or are the most convenient to use it as composable)
For example Nuxt's useCookie or composables shortcuts generated from graphql-generator-urql (useFooQuery etc.)
(and Urql has also guard disallowing when called outside context, raising use* functions may only be called during the
setup()
... error)Beta Was this translation helpful? Give feedback.
All reactions