Recursive Store
This example features a store that contains other objects rather than just primitives. The store.counter
property is an object literal.
The example doesn't work as is, because by default the useStore
function only watches top-level properties.
To make the example work, you need to do one of two things:
-
Wrap
{count:0}
in anotheruseStore()
call (which is a bit cumbersome) -
Allow
useStore
to recursively apply reactivity to all properties by passing the additional argument:{recursive:true}
.
Your task: Update the sample with the
useStore()
function.
Note that stores are not tied to any single component. In fact, you can pass stores from one component to another.
Edit Tutorial