render components from an array with the name of the components (as strings) #5592
-
Array: how would I render these four components with only the name of the component stored as strings in an array? the solution has to be dynamic so it shouldn't matter how many components or what the component is. Thanks! |
Beta Was this translation helpful? Give feedback.
Answered by
stephane-vanraes
Jul 19, 2022
Replies: 1 comment 3 replies
-
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]} /> |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
tryggs
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You would have to create some mapping from string to actual component:
and then use that instead: