Skip to content
Discussion options

You must be logged in to vote

You will need to always return data from a load function as an object. Currently, get_menus() is returning an array of objects.

/** @type {import('./$types').LayoutServerLoad} */
export async function load() {
	let menus = await get_menus();
        console.log(typeof (menus))
	console.log(menus);
-       return menus;
+       return { menus };
}

Now, load is returning an object with the menus key.

Next, we can extract the menus key from data, declare, and set it all at once.

You can also use generated types to get the autocomplete and suggestions for the returned object from load.

<script lang="ts">
+       import type { PageData } from './$types';

-	export let data: Object = {};
+

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@einarpersson
Comment options

@eltigerchino
Comment options

@magic-thomas
Comment options

@eltigerchino
Comment options

@magic-thomas
Comment options

Answer selected by magic-thomas
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants