Reputation: 5958
In Svelte I can read from store using $
symbol:
<script>
export let myStore;
</script>
<p>
{$myStore}
</p>
How do I read from store that is a property of an object? E.g. let's say foo.store
is a store.
I have tried $foo.store
, $(foo.store)
and foo.$store
, neither working!
I am aware I can do let foo_store = foo.store
and then $foo_store
, but I'm looking for a simpler way.
EDIT looking for solution for assignments to store too.
Upvotes: 6
Views: 1384
Reputation: 29585
The short answer is that you can't — for the purposes of the syntactic sugar, stores are always free variables. For that reason it's common to use destructuring:
const { x, y, z } = stores;
Upvotes: 5