Skip to content

Commit 91510a0

Browse files
authored
Merge pull request #19 from inertiajs/when-visible-fetching
Added `fetching` state docs to `<WhenVisible>` component
2 parents 0722e8a + 0b776ee commit 91510a0

File tree

2 files changed

+81
-1
lines changed

2 files changed

+81
-1
lines changed

v2/data-props/load-when-visible.mdx

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,86 @@ export default () => (
323323

324324
</CodeGroup>
325325

326+
### Fetching State
327+
328+
The `WhenVisible` component exposes a `fetching` slot prop that you may use to display a loading indicator during subsequent requests. This is useful because the `fallback` is only shown on the initial load, while `fetching` allows you to indicate that data is being refreshed on subsequent loads.
329+
330+
<CodeGroup>
331+
332+
```vue Vue icon="vuejs"
333+
<script setup>
334+
import { WhenVisible } from '@inertiajs/vue3'
335+
</script>
336+
337+
<template>
338+
<WhenVisible data="permissions" always>
339+
<template #default="{ fetching }">
340+
<PermissionsChildComponent />
341+
<div v-if="fetching">Refreshing...</div>
342+
</template>
343+
344+
<template #fallback>
345+
<div>Loading...</div>
346+
</template>
347+
</WhenVisible>
348+
</template>
349+
```
350+
351+
```jsx React icon="react"
352+
import { WhenVisible } from '@inertiajs/react'
353+
354+
export default () => (
355+
<WhenVisible data="permissions" always fallback={() => <div>Loading...</div>}>
356+
{({ fetching }) => (
357+
<>
358+
<PermissionsChildComponent />
359+
{fetching && <div>Refreshing...</div>}
360+
</>
361+
)}
362+
</WhenVisible>
363+
)
364+
```
365+
366+
```svelte Svelte 4 icon="s"
367+
<script>
368+
import { WhenVisible } from '@inertiajs/svelte'
369+
370+
export let permissions
371+
</script>
372+
373+
<WhenVisible data="permissions" always let:fetching>
374+
<PermissionsChildComponent />
375+
{#if fetching}
376+
<div>Refreshing...</div>
377+
{/if}
378+
379+
<svelte:fragment slot="fallback">
380+
<div>Loading...</div>
381+
</svelte:fragment>
382+
</WhenVisible>
383+
```
384+
385+
```svelte Svelte 5 icon="s"
386+
<script>
387+
import { WhenVisible } from '@inertiajs/svelte'
388+
389+
let { permissions } = $props()
390+
</script>
391+
392+
<WhenVisible data="permissions" always let:fetching>
393+
<PermissionsChildComponent />
394+
{#if fetching}
395+
<div>Refreshing...</div>
396+
{/if}
397+
398+
{#snippet fallback()}
399+
<div>Loading...</div>
400+
{/snippet}
401+
</WhenVisible>
402+
```
403+
404+
</CodeGroup>
405+
326406
## Form Submissions
327407

328408
When submitting forms, you may want to use the `except` option to exclude the props that are being used by the `WhenVisible` component. This prevents the props from being reloaded when you get redirected back to the current page because of validation errors.

v2/data-props/shared-data.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class HandleInertiaRequests extends Middleware
7777
}
7878
```
7979

80-
You may also share once props manually using the `Inertia::shareOnce()`.
80+
You may also share once props manually using the `Inertia::shareOnce()` method.
8181

8282
```php
8383
Inertia::shareOnce('countries', fn () => Country::all());

0 commit comments

Comments
 (0)