Menu

Nuxt useFetch Addons: Stop Forking the Composable for Polling and Auth
📰

Nuxt useFetch Addons: Stop Forking the Composable for Polling and Auth

DEV Community: vue·Danny Holloran·about 8 hours ago
#eN4i0Pq0
#devtovue#devto#dev#options#const
Long article (1251 words) — no AI summary yet.
Reading 0:00
15s threshold

Every Nuxt app I've worked on eventually grows a useApi wrapper. It starts innocently: a base URL and an auth header. Then someone needs polling on the dashboard, so a poll option gets bolted on. Then retries. Then "refresh when the tab comes back into focus." Six months later the wrapper is 200 lines, its types are a pile of Omit<> and Partial<> , and nobody wants to touch it because every page in the app goes through it.

Nuxt 4.4 gave us createUseFetch and createUseAsyncData , which fixed the first half of that story: you can stamp out a typed useFetch with your own defaults instead of wrapping it. Nuxt 4.6 fixes the second half with addons . An addon is a small, reusable unit of behavior you hand to the factory. It can declare new call-site options (fully typed), hook into the request, wrap the handler in middleware, and add properties to what the composable returns.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.