Can I use for this?
Hey lovely people! Is there a way to abstract this? That way the code would be less verbose and I won't have to add a new line to conditionally render every new component I create.
{#if JSON.parse(content).tag == "Table"}
<Table {...JSON.parse(content).props} />
{:else if JSON.parse(content).tag == "Chart"}
<Chart {...JSON.parse(content).props} />
{:else if JSON.parse(content).tag == "Barchart"}
<Barchart {...JSON.parse(content).props} />
{:else if JSON.parse(content).tag == "Piechart"}
<Piechart {...JSON.parse(content).props} />
{/if}
From the docs, I thought that <svelte:element> would serve this purpose but I haven't gotten it to work:
<svelte:element this={JSON.parse(content).tag} {...JSON.parse(content).props} />
Thanks!