Skip to content

Commit 4fa77d0

Browse files
committed
docs: update fetch type
1 parent 50f9b53 commit 4fa77d0

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

docs/3.api/2.composables/use-async-data.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ function useAsyncData<DataT, DataE>(
170170
options?: AsyncDataOptions<DataT>
171171
): AsyncData<DataT, DataE>
172172
function useAsyncData<DataT, DataE>(
173-
key: string | Ref<string> | ComputedRef<string>,
173+
key: MaybeRefOrGetter<string>,
174174
handler: (nuxtApp?: NuxtApp) => Promise<DataT>,
175175
options?: AsyncDataOptions<DataT>
176176
): Promise<AsyncData<DataT, DataE>>
@@ -184,7 +184,7 @@ type AsyncDataOptions<DataT> = {
184184
default?: () => DataT | Ref<DataT> | null
185185
transform?: (input: DataT) => DataT | Promise<DataT>
186186
pick?: string[]
187-
watch?: WatchSource[] | false
187+
watch?: MultiWatchSources | false
188188
getCachedData?: (key: string, nuxtApp: NuxtApp, ctx: AsyncDataRequestContext) => DataT | undefined
189189
}
190190

@@ -194,11 +194,12 @@ type AsyncDataRequestContext = {
194194
}
195195

196196
type AsyncData<DataT, ErrorT> = {
197-
data: Ref<DataT | null>
197+
data: Ref<DataT | undefined>
198+
pending: Ref<boolean>
198199
refresh: (opts?: AsyncDataExecuteOptions) => Promise<void>
199200
execute: (opts?: AsyncDataExecuteOptions) => Promise<void>
200201
clear: () => void
201-
error: Ref<ErrorT | null>
202+
error: Ref<ErrorT | undefined>
202203
status: Ref<AsyncDataRequestStatus>
203204
};
204205

docs/3.api/2.composables/use-fetch.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ function useFetch<DataT, ErrorT>(
103103
): Promise<AsyncData<DataT, ErrorT>>
104104

105105
type UseFetchOptions<DataT> = {
106-
key?: string
106+
key?: MaybeRefOrGetter<string>
107107
method?: string
108108
query?: SearchParams
109109
params?: SearchParams
@@ -119,7 +119,8 @@ type UseFetchOptions<DataT> = {
119119
default?: () => DataT
120120
transform?: (input: DataT) => DataT | Promise<DataT>
121121
pick?: string[]
122-
watch?: WatchSource[] | false
122+
$fetch?: typeof globalThis.$fetch
123+
watch?: MultiWatchSources | false
123124
}
124125

125126
type AsyncDataRequestContext = {
@@ -128,11 +129,12 @@ type AsyncDataRequestContext = {
128129
}
129130

130131
type AsyncData<DataT, ErrorT> = {
131-
data: Ref<DataT | null>
132+
data: Ref<DataT | undefined>
133+
pending: Ref<boolean>
132134
refresh: (opts?: AsyncDataExecuteOptions) => Promise<void>
133135
execute: (opts?: AsyncDataExecuteOptions) => Promise<void>
134136
clear: () => void
135-
error: Ref<ErrorT | null>
137+
error: Ref<ErrorT | undefined>
136138
status: Ref<AsyncDataRequestStatus>
137139
}
138140

@@ -151,7 +153,7 @@ type AsyncDataRequestStatus = 'idle' | 'pending' | 'success' | 'error'
151153
152154
| Option | Type | Default | Description |
153155
| ---| --- | --- | --- |
154-
| `key` | `string` | auto-gen | Unique key for de-duplication. If not provided, generated from URL and options. |
156+
| `key` | `MaybeRefOrGetter<string>` | auto-gen | Unique key for de-duplication. If not provided, generated from URL and options. |
155157
| `method` | `string` | `'GET'` | HTTP request method. |
156158
| `query` | `object` | - | Query/search params to append to the URL. Alias: `params`. Supports refs/computed. |
157159
| `params` | `object` | - | Alias for `query`. |
@@ -167,10 +169,10 @@ type AsyncDataRequestStatus = 'idle' | 'pending' | 'success' | 'error'
167169
| `transform` | `(input: DataT) => DataT \| Promise<DataT>` | - | Function to transform the result after resolving. |
168170
| `getCachedData`| `(key, nuxtApp, ctx) => DataT \| undefined` | - | Function to return cached data. See below for default. |
169171
| `pick` | `string[]` | - | Only pick specified keys from the result. |
170-
| `watch` | `WatchSource[] \| false` | - | Array of reactive sources to watch and auto-refresh. `false` disables watching. |
172+
| `watch` | `MultiWatchSources \| false` | - | Array of reactive sources to watch and auto-refresh. `false` disables watching. |
171173
| `deep` | `boolean` | `false` | Return data in a deep ref object. |
172174
| `dedupe` | `'cancel' \| 'defer'` | `'cancel'` | Avoid fetching same key more than once at a time. |
173-
| `$fetch` | `typeof $fetch` | - | Custom $fetch implementation. |
175+
| `$fetch` | `typeof globalThis.$fetch` | - | Custom $fetch implementation. |
174176
175177
::note
176178
All fetch options can be given a `computed` or `ref` value. These will be watched and new requests made automatically with any new values if they are updated.
@@ -190,6 +192,7 @@ This only caches data when `experimental.payloadExtraction` in `nuxt.config` is
190192
| Name | Type | Description |
191193
| --- | --- |--- |
192194
| `data` | `Ref<DataT \| null>` | The result of the asynchronous fetch. |
195+
| `pending` | `Ref<boolean>` | [For specific explanations](https://nuxt.com/docs/getting-started/upgrade#alignment-of-pending-value-in-useasyncdata-and-usefetch) |
193196
| `refresh` | `(opts?: AsyncDataExecuteOptions) => Promise<void>` | Function to manually refresh the data. By default, Nuxt waits until a `refresh` is finished before it can be executed again. |
194197
| `execute` | `(opts?: AsyncDataExecuteOptions) => Promise<void>` | Alias for `refresh`. |
195198
| `error` | `Ref<ErrorT \| null>` | Error object if the data fetching failed. |

0 commit comments

Comments
 (0)