Dealing with the new data prop: accessing layout data in page, and accessing stores in data #6145
Unanswered
kevinrenskers
asked this question in
Q&A
Replies: 1 comment 1 reply
-
I had a similar issue at first, but when moving to 427 it seemed to magically work without any additional snippet in the With regards to the stores, that is something that I am also trying to figure out :) |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to migrate to 414, and one of the things I am bumping into is the new single data prop. Two questions about this.
First question. If the
+layout.jsload function returns an object with data, I can easily consume this data in+layout.svelte, by usingexport let data. But if I want to use that same data within+page.svelteas well, I have to create a+page.jsfile with this oneliner.Why is this necessary, why can't the page access the data as returned by the layout directly?
Second question. If the data as returned by the layout contains a store, how can I easily work with this? For example, I used to have this code in my route file:
And then within the Svelte file I could use
usereverywhere, which is a proper user object (keep in mindfetchedUseritself is a store). But now with the single data prop, I can't accessdata.$fetchedUser, that doesn't work. So I have to do something like this:This takes an extra line for every single property that I use, and there are quite a few of them. Is there an easier way to subscribe to the store? Something like
$: user = data.$fetchedUser, but then working of course :)Or in other words, this used to work:
But now I have to create this intermediate property because
data.$fetchedUserisn't supported:Beta Was this translation helpful? Give feedback.
All reactions