Confused on +layout.js and +layout.svelte props passed in load() function…

I have a load function in my root +layout.js file that is:

export async function load() {
// and all it returns is
return {
prop1: true,
prop2: false,
prop3: “value 3”
};

For the life of me, I cannot do anything in the +layout.svelte file to m…


This content originally appeared on DEV Community and was authored by Jim Nayzium

I have a load function in my root +layout.js file that is:

export async function load() {
// and all it returns is
return {
prop1: true,
prop2: false,
prop3: "value 3"
};

For the life of me, I cannot do anything in the +layout.svelte file to make these values show up.

export let prop1;
export let prop2;
export let prop3;
console.log("prop1 = " + prop1);

gives me "prop1 undefined" in the console every time!
I have tried deconstructing the export like

let { prop1 } = data;
// and
let { prop1 } = props;

and nothing works... no matter what I do!

Is it because the load function is async? I need it to be async so I can fetch some external api's when it's done, but I was just testing the bare bones to try and understand how things worked.

Any ideas on the load order of

+page.js vs +layout.js
+page.svelte vs +layout.svelte

etc?


This content originally appeared on DEV Community and was authored by Jim Nayzium


Print Share Comment Cite Upload Translate Updates
APA

Jim Nayzium | Sciencx (2024-07-16T16:11:29+00:00) Confused on +layout.js and +layout.svelte props passed in load() function…. Retrieved from https://www.scien.cx/2024/07/16/confused-on-layout-js-and-layout-svelte-props-passed-in-load-function/

MLA
" » Confused on +layout.js and +layout.svelte props passed in load() function…." Jim Nayzium | Sciencx - Tuesday July 16, 2024, https://www.scien.cx/2024/07/16/confused-on-layout-js-and-layout-svelte-props-passed-in-load-function/
HARVARD
Jim Nayzium | Sciencx Tuesday July 16, 2024 » Confused on +layout.js and +layout.svelte props passed in load() function…., viewed ,<https://www.scien.cx/2024/07/16/confused-on-layout-js-and-layout-svelte-props-passed-in-load-function/>
VANCOUVER
Jim Nayzium | Sciencx - » Confused on +layout.js and +layout.svelte props passed in load() function…. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/07/16/confused-on-layout-js-and-layout-svelte-props-passed-in-load-function/
CHICAGO
" » Confused on +layout.js and +layout.svelte props passed in load() function…." Jim Nayzium | Sciencx - Accessed . https://www.scien.cx/2024/07/16/confused-on-layout-js-and-layout-svelte-props-passed-in-load-function/
IEEE
" » Confused on +layout.js and +layout.svelte props passed in load() function…." Jim Nayzium | Sciencx [Online]. Available: https://www.scien.cx/2024/07/16/confused-on-layout-js-and-layout-svelte-props-passed-in-load-function/. [Accessed: ]
rf:citation
» Confused on +layout.js and +layout.svelte props passed in load() function… | Jim Nayzium | Sciencx | https://www.scien.cx/2024/07/16/confused-on-layout-js-and-layout-svelte-props-passed-in-load-function/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.