nowfound

Life & fun · February 8, 2020

How to pass a Svelte component to another Svelte component

Using allows you to pass Svelte components to another Svelte component dynamically, and not adding so much markup on a single Svelte component.

How to pass a Svelte component to another Svelte component launched on February 8, 2020 with 6 votes, #1,040 of 3,162 launches that month and more than 50% of that year's launches. The site was still online in September 2026, 6 years on.

What it does

How in the world do you pass a Svelte component down to another Svelte component ? But that method has its limitations. The <slot> directive cannot be dynamic. For example, what if you have an array of Svelte components? Since the <slot> directive cannot be dynamic, how do you handle this type of scenario? To pass Svelte components dynamically down to a child component you have to use Svelte&#8217;s <svelte:component> directive. If the property this has a component attach to it than it will render the given Svelte component. But if the value is falsy ( false , undefined , null ) than it will not render. In a recent article, I created a very simple Svelte Tab component. You can find the…from linguinecode.com

Does a similar job

all alternatives →

More life & fun this month

the category →

Source: Show HN post ↗

Launched alongside, February 2020

the whole month →