Skip to content

How to bind the data to slot #13109

Answered by brunnerh
karchung0930 asked this question in Q&A
Discussion options

You must be logged in to vote

You cannot pass data to slots in SvelteKit since the code that uses the components is autogenerated.
Slot properties also cannot be bound, they are one-way.

Your options are either:

  • Using the layout's load function - any data returned from there will be available in the data property of the layout and any child layouts/pages.
    The data cannot be changed in a child to update the parent.
  • Setting it as a context - the context can be retrieved in any descendant.
    If the data should be reactive from child to parents (e.g. the page changes the value and the layout updates), you need to use a writable store (or in Svelte 5 a $state object whose properties can be changed).

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by karchung0930
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants