You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/docs/src/pages/tutorial/store/recursive/index.mdx
+10-5Lines changed: 10 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,11 +3,16 @@ title: Recursive Store
3
3
layout: tutorial
4
4
---
5
5
6
-
In this example, we have created a store that contains other objects rather than just primitives. (`store.counter` is object literal.)
6
+
This example features a store that contains other objects rather than just primitives. The `store.counter`property is an object literal.
7
7
8
-
The example does not work, because by default the `useStore` only sets up watches on top-level properties. To make the example work, we need to either:
9
-
1. wrap the `{count:0}` in another `useStore()` call, which is cumbersome OR
10
-
2. ask the `useStore` to apply reactivity to all properties recursively by passing the additional argument `{recursive:true}`.
8
+
The example doesn't work as is, because by default the `useStore` function only watches top-level properties.
11
9
10
+
To make the example work, you need to do one of two things:
12
11
13
-
Notice that it is perfectly OK (and encouraged) to pass the stores to other components. (Stores are not tied to any one component.)
12
+
1. Wrap `{count:0}` in another `useStore()` call (which is a bit cumbersome)
13
+
14
+
1. Allow `useStore` to recursively apply reactivity to all properties by passing the additional argument: `{recursive:true}`.
15
+
16
+
> **Your task:** Update the sample with the `useStore()` function.
17
+
18
+
Note that stores are not tied to any single component. In fact, you can pass stores from one component to another.
0 commit comments