Skip to content

Commit

Permalink
docs: document derived use of $app/state's page (#13346)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdhuntington authored Jan 20, 2025
1 parent 18d69fb commit f5103c6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/kit/src/runtime/app/state/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ import { BROWSER } from 'esm-env';
* {/if}
* ```
*
* Changes to `page` are available exclusively with runes. (The legacy reactivity syntax will not reflect any changes)
*
* ```svelte
* <!--- file: +page.svelte --->
* <script>
* import { page } from '$app/state';
* const id = $derived(page.params.id); // This will correctly update id for usage on this page
* $: badId = page.params.id; // Do not use; will never update after initial load
* </script>
* ```
*
* On the server, values can only be read during rendering (in other words _not_ in e.g. `load` functions). In the browser, the values can be read at any time.
*
* @type {import('@sveltejs/kit').Page}
Expand Down
11 changes: 11 additions & 0 deletions packages/kit/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2356,6 +2356,17 @@ declare module '$app/state' {
* {/if}
* ```
*
* Changes to `page` are available exclusively with runes. (The legacy reactivity syntax will not reflect any changes)
*
* ```svelte
* <!--- file: +page.svelte --->
* <script>
* import { page } from '$app/state';
* const id = $derived(page.params.id); // This will correctly update id for usage on this page
* $: badId = page.params.id; // Do not use; will never update after initial load
* </script>
* ```
*
* On the server, values can only be read during rendering (in other words _not_ in e.g. `load` functions). In the browser, the values can be read at any time.
*
* */
Expand Down

0 comments on commit f5103c6

Please sign in to comment.