|
1 | 1 | <script lang="ts"> |
2 | | - import { inertia, page, useForm } from '@inertiajs/svelte' |
| 2 | + import { inertia, page, usePage, useForm } from '@inertiajs/svelte' |
3 | 3 | import { onMount } from 'svelte' |
4 | 4 |
|
| 5 | + type PageProps = { |
| 6 | + foo: string |
| 7 | + } |
| 8 | +
|
5 | 9 | export let foo |
6 | 10 |
|
7 | 11 | const form = useForm({ foo }) |
8 | 12 |
|
| 13 | + const pageProps: PageProps = { |
| 14 | + foo: $page.props.foo, |
| 15 | + } |
| 16 | +
|
| 17 | + const sveltePage = usePage<PageProps>() |
| 18 | +
|
9 | 19 | console.log('[script] foo prop is', foo) |
10 | 20 | console.log('[script] $page.props.foo is', $page.props.foo) |
| 21 | + console.log('[script] $sveltePage.props.foo is', $sveltePage.props.foo) |
11 | 22 |
|
12 | 23 | $: console.log('[reactive expression] foo prop is', foo) |
13 | 24 | $: console.log('[reactive expression] $page.props.foo is', $page.props.foo) |
| 25 | + $: console.log('[reactive expression] $sveltePage.props.foo is', $sveltePage.props.foo) |
14 | 26 |
|
15 | 27 | onMount(() => { |
16 | 28 | console.log('[onMount] foo prop is', foo) |
17 | 29 | console.log('[onMount] $page.props.foo is', $page.props.foo) |
| 30 | + console.log('[onMount] $sveltePage.props.foo is', $sveltePage.props.foo) |
18 | 31 | }) |
19 | | -
|
20 | | - type PageProps = { |
21 | | - foo: string |
22 | | - } |
23 | | -
|
24 | | - const pageProps: PageProps = { |
25 | | - foo: $page.props.foo, |
26 | | - } |
27 | 32 | </script> |
28 | 33 |
|
29 | 34 | <div> |
30 | 35 | <input id="input" type="text" bind:value={$form.foo} /> |
31 | 36 | <p>foo prop is {foo}</p> |
32 | 37 | <p>$page.props.foo is {$page.props.foo}</p> |
33 | 38 | <p>pageProps.foo is {pageProps.foo}</p> |
| 39 | + <p>$sveltePage.props.foo is {$sveltePage.props.foo}</p> |
34 | 40 |
|
35 | 41 | <a href="/svelte/props-and-page-store" use:inertia={{ data: { foo: 'bar' } }}> Bar </a> |
36 | 42 | <a href="/svelte/props-and-page-store" use:inertia={{ data: { foo: 'baz' } }}> Baz </a> |
|
0 commit comments