@@ -229,8 +229,9 @@ export default function () {
229
229
/>
230
230
231
231
< P >
232
- To make this even easier, Inertia offers a prefetch helper. This helper provides some additional insight into
233
- the request, such as the last updated timestamp and if the request is currently prefetching.
232
+ Inertia also provides a < Code > usePrefetch</ Code > hook that allows you to track the prefetch state for the
233
+ current page. It returns information about whether the page is currently prefetching, has been prefetched,
234
+ when it was last updated, and a < Code > flush</ Code > method that flushes the cache for the current page only.
234
235
</ P >
235
236
236
237
< TabbedCode
@@ -241,11 +242,7 @@ export default function () {
241
242
code : dedent `
242
243
import { usePrefetch } from '@inertiajs/vue3'
243
244
244
- const { lastUpdatedAt, isPrefetching, isPrefetched } = usePrefetch(
245
- '/users',
246
- { method: 'get', data: { page: 2 } },
247
- { cacheFor: '1m' },
248
- )
245
+ const { lastUpdatedAt, isPrefetching, isPrefetched, flush } = usePrefetch()
249
246
` ,
250
247
} ,
251
248
{
@@ -254,11 +251,7 @@ export default function () {
254
251
code : dedent `
255
252
import { usePrefetch } from '@inertiajs/react'
256
253
257
- const { lastUpdatedAt, isPrefetching, isPrefetched } = usePrefetch(
258
- '/users',
259
- { method: 'get', data: { page: 2 } },
260
- { cacheFor: '1m' },
261
- )
254
+ const { lastUpdatedAt, isPrefetching, isPrefetched, flush } = usePrefetch()
262
255
` ,
263
256
} ,
264
257
{
@@ -267,11 +260,47 @@ export default function () {
267
260
code : dedent `
268
261
import { usePrefetch } from '@inertiajs/svelte'
269
262
270
- const { lastUpdatedAt, isPrefetching, isPrefetched } = usePrefetch(
271
- '/users',
272
- { method: 'get', data: { page: 2 } },
273
- { cacheFor: '1m' },
274
- )
263
+ const { lastUpdatedAt, isPrefetching, isPrefetched, flush } = usePrefetch()
264
+ ` ,
265
+ } ,
266
+ ] }
267
+ />
268
+ < P >
269
+ You can also pass visit options when you need to differentiate between different request configurations for the same URL.
270
+ </ P >
271
+ < TabbedCode
272
+ examples = { [
273
+ {
274
+ name : 'Vue' ,
275
+ language : 'js' ,
276
+ code : dedent `
277
+ import { usePrefetch } from '@inertiajs/vue3'
278
+
279
+ const { lastUpdatedAt, isPrefetching, isPrefetched, flush } = usePrefetch({
280
+ headers: { 'X-Custom-Header': 'value' }
281
+ })
282
+ ` ,
283
+ } ,
284
+ {
285
+ name : 'React' ,
286
+ language : 'js' ,
287
+ code : dedent `
288
+ import { usePrefetch } from '@inertiajs/react'
289
+
290
+ const { lastUpdatedAt, isPrefetching, isPrefetched, flush } = usePrefetch({
291
+ headers: { 'X-Custom-Header': 'value' }
292
+ })
293
+ ` ,
294
+ } ,
295
+ {
296
+ name : 'Svelte' ,
297
+ language : 'js' ,
298
+ code : dedent `
299
+ import { usePrefetch } from '@inertiajs/svelte'
300
+
301
+ const { lastUpdatedAt, isPrefetching, isPrefetched, flush } = usePrefetch({
302
+ headers: { 'X-Custom-Header': 'value' }
303
+ })
275
304
` ,
276
305
} ,
277
306
] }
@@ -286,8 +315,7 @@ export default function () {
286
315
< Code > router.flush</ Code > method.
287
316
</ P >
288
317
< P >
289
- Furthermore, if you are using the prefetch helper, it will return a < Code > flush</ Code > method for you to use for
290
- that specific page.
318
+ Furthermore, if you are using the < Code > usePrefetch</ Code > hook, it will return a < Code > flush</ Code > method for you to use.
291
319
</ P >
292
320
< TabbedCode
293
321
examples = { [
@@ -304,12 +332,9 @@ export default function () {
304
332
{ method: 'get', data: { page: 2 } },
305
333
)
306
334
307
- const { flush } = usePrefetch(
308
- '/users',
309
- { method: 'get', data: { page: 2 } },
310
- )
335
+ const { flush } = usePrefetch()
311
336
312
- // Flush cache for a specific page
337
+ // Flush cache for the current page
313
338
flush()
314
339
` ,
315
340
} ,
0 commit comments