0Pricing
Sveltejs Academy · Lesson

Returning Data and Using $page.data

Return data from load and access it in the page component via the data prop.

The data Prop

The page receives a special data prop populated from the load function return.

<!-- +page.svelte -->
<script>
  export let data;
</script>
<ul>{#each data.items as it}<li>{it.name}</li>{/each}</ul>

Type Safe

With TypeScript, SvelteKit generates types from load to data automatically.

<script lang="ts">
  import type { PageData } from "./$types";
  export let data: PageData;
</script>

All lessons in this course

  1. +page.js load Function
  2. Returning Data and Using $page.data
  3. Error Handling in load
  4. +page.server.js for Server-Only Logic
← Back to Sveltejs Academy