Quantcast
Channel: Active questions tagged svelte - Stack Overflow
Viewing all articles
Browse latest Browse all 1541

How can I render a component in its own component (recursively) in svelte?

$
0
0

I'm trying to make a recursive component that acts as a sort of tree view, where the component takes in an array.

App.svelte

<script>    import Tree from "./Tree.svelte"    let name = 'world';</script><Tree arrayTree={[1, 2, [3, 4], 5, 6, 7, [8, [9, 10]], 11, 12]}/>

Tree.svelte

<script>    export let arrayTree = []    export let level = 0</script>{#each arrayTree as branch}    {#if Array.isArray(branch)}<!-- How do I do this? -->    {:else}<p>{'-'.repeat(level)}{branch}</p>    {/if}{/each}

My goal is to re-render the component inside, but I can't re-call <Tree> inside the component, or else it says: Tree is not defined. Is there any way that I can accomplish this?

Svelte REPL


Viewing all articles
Browse latest Browse all 1541

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>