Skip to content

Conversation

@Sveb
Copy link
Contributor

@Sveb Sveb commented Oct 3, 2025

After researching it a lot, I found that the useFetch is a composable designed to fetch on server.
Here in the docs it says that it's meant to be called directly in a setup function, plugin or route middleware, meaning it can't be inside of a if conditional statement or a function.
https://nuxt.com/docs/4.x/api/composables/use-fetch#:~:text=API%20response%20type.-,useFetch,re%2D[…]t%20side%20when%20the%20page%20hydrates.,-Usage
I found it's best to use useAysncData if we want conditional fetching.

Sveb added 4 commits October 3, 2025 15:27
- the composable useWpFetch wrapping the Vue Composable useFetch can't be used inside of a conditional or a function, always fetches data regardless.
- useFetch can be used only inside top level of script setup or another comaposable
@Sveb Sveb requested a review from drewbaker October 3, 2025 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant