Skip to main content
InterviewHubPRO
Section Overview
Q13

Question 13 of 50

Part 2: Core Architecture & Data Fetching (Mid-Level)

26%
Nuxt & Universal SSR (50 Qs)•Part 2: Core Architecture & Data Fetching (Mid-Level)

What is the difference between `useFetch()` and `useAsyncData()`?

senior LevelCode ExampleAsync & PromisesSystem DesignHTTP & REST APIs

In Simple Words:

  • useAsyncData() is the foundational wrapper that manages asynchronous SSR serialization, caching keys, loading states, and hydration reconciliation for any promise.
  • useFetch(url) is a convenient syntactic sugar built directly on top of useAsyncData() and $fetch. It automatically generates an internal cache key based on the URL and query parameters.

Comparison Matrix:

FeatureuseFetch(url, options)useAsyncData(key, handler)
Primary UseDirect HTTP endpointsAny custom async logic (DB calls, multi-API join, SDKs)
Cache KeyAuto-generated from URLManually supplied string key
ReactivityAutomatically re-fetches when reactive query changesRequires watch option or manual refresh()
typescript
// useFetch: Simple HTTP endpoint
const { data: user, pending, error, refresh } = await useFetch('/api/user', {
  query: { id: userId }
});

// useAsyncData: Complex promise aggregation
const { data: dashboard } = await useAsyncData('dashboard-data', async () => {
  const [stats, notifications] = await Promise.all([
    $fetch('/api/stats'),
    $fetch('/api/notifications')
  ]);
  return { stats, notifications };
});