Skip to main content
InterviewHubPRO
Section Overview
Q39

Question 39 of 50

Part 3: Advanced Internals, Performance & Production (Senior / Staff)

78%
Nuxt & Universal SSR (50 Qs)•Part 3: Advanced Internals, Performance & Production (Senior / Staff)

`useAsyncData` vs `$fetch` in Nuxt 3: Deduplication and Hydration Lifecycle.

senior LevelCode ExampleFormsLifecyclePerformance

In Simple Words:

  • $fetch: Nuxt's enhanced HTTP client. If called directly in <script setup> without useAsyncData, it executes twice: once on the server during SSR and once again on the client during hydration.
  • useAsyncData(key, () => $fetch(...)): Wraps $fetch in a unique key. It fetches on the server, serializes the response into the page HTML, and immediately resolves on the client from the cache without a duplicate network request.
typescript
// ✅ Correct: Only 1 network request made during SSR + Client hydration
const { data: profile, pending, error } = await useAsyncData(
  'user-profile',
  () => $fetch('/api/user/profile')
);