Skip to content

[mount] Svelte 5, create .svelte component **with content** from JS (programatically) #15105

Answered by brunnerh
Neah-Ko asked this question in Q&A
Discussion options

You must be logged in to vote

It depends on what the content is and where it is supposed to come from. You can e.g. reference snippets defined in the markup and snippets that don't use local state can also be exported from the module script. That may be easier than working with createRawSnippet which is not really meant for general use.

One can also import components and pass those as props & add them in the receiving component's markup.

Regarding the approach using createRawSnippet, that works if the Card actually renders children.
If that is not the case, the library may still be using <slot />.
You could create a wrapper component as a workaround (so you have <Card {...rest}>{@render children()}</Card>).

Though if …

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@Neah-Ko
Comment options

@Neah-Ko
Comment options

@brunnerh
Comment options

@Neah-Ko
Comment options

Answer selected by Neah-Ko
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