Skip to content

render components from an array with the name of the components (as strings) #5592

Answered by stephane-vanraes
tryggs asked this question in Q&A
Discussion options

You must be logged in to vote

You would have to create some mapping from string to actual component:

const mapping = {
   "Comp1": Comp1,
   "Comp2": Comp2
}

and then use that instead:

<svelte:component this={mapping[component]} />

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@tryggs
Comment options

@stephane-vanraes
Comment options

@tryggs
Comment options

Answer selected by tryggs
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