Eric Anderson
Eric Anderson

Reputation: 341

Can you pass an array thru props in Svelte?

Can you pass an array through props in Svelte?

<script>
    import List
    let array = [];
    console.log(array);
</script>

<List list=array/>
<script>
    export let array;
    console.log(array);
</script>

This will produce: (1st log) [] (2nd log) array

But I thought it would produce (1st log) [] (2nd log) []

Upvotes: 1

Views: 4841

Answers (1)

Rich Harris
Rich Harris

Reputation: 29585

Yes, you can pass any value as a prop.

The problem here is that you're doing list=array, which is just passing the string "array", rather than list={array}. See the tutorial to learn the syntax.

Upvotes: 6

Related Questions