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

How do I pass the value of a store as a prop in Svelte, where the store is an object member?

$
0
0

Suppose I have a list of items with Svelte stores as members, e.g.:

interface Item {  isAvailable: Writable<boolean>;}

If I have some component with a boolean prop, how do I pass values from those stores to that prop if I'm iterating over the items?

I would have thought there'd be some straightforward syntax resembling this:

{#each items as item}<Component isEnabled={item.$isAvailable} />{/each}

The best solution I can think of would be defining another component something like:

<script>  export let item: Item;  $: isAvailable = item.isAvailable;</script><Component isEnabled={$isAvailable} />

But that seems like an excessive amount of boilerplate.


Viewing all articles
Browse latest Browse all 1662

Trending Articles



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