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: README.md
+13-17Lines changed: 13 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,15 +4,15 @@
4
4
5
5
## ScopeProvider
6
6
7
-
`<ScopeProvider>` lets you reuse the *same* atoms in different parts of the React tree **without sharing state** while still be able to read other atoms from the parent store.
7
+
`<ScopeProvider>` lets you reuse the *same* atoms in different parts of the React tree **without sharing state** while still being able to read other atoms from the parent store.
8
8
9
9
---
10
10
11
11
### At‑a‑glance
12
12
13
-
* Scopes are opt‑in. Only atoms listed in `atoms` or `atomFamilies`.
13
+
* Scopes are opt‑in. Only atoms listed in `atoms` or `atomFamilies` are explicitly scoped.
14
14
***Unscoped derived** atoms can read both unscoped and scoped atoms.
15
-
***Scoped derived** atoms implicitly scope their atom dependencies. When you scope a derived atom, every atom it touches (recursive) is scoped automatically, but only when read by the derived atom. Outside the derived atom, it continues to be unscoped.
15
+
***Scoped derived** atoms implicitly scope their atom dependencies. When you scope a derived atom, every atom it touches (recursively) is scoped automatically, but only when read by the derived atom. Outside the derived atom, it continues to be unscoped.
16
16
***Nested lookup.** If a scope can’t find the atom in the current scope, it inherits from the nearest parent scope, up to the nearest store.
17
17
* Scoping works for both reading from atoms *and* writing to atoms.
18
18
@@ -54,7 +54,7 @@ export default function App() {
54
54
}
55
55
```
56
56
57
-
The second counter owns a private `doubledAtom`*and* a private `countAtom` because`doubledAtom` is scoped.
57
+
The second counter owns a private `doubledAtom`*and* a private `countAtom` because`doubledAtom` is scoped.
58
58
59
59
---
60
60
@@ -70,15 +70,15 @@ The second counter owns a private `doubledAtom` *and* a private `countAtom` b
70
70
```
71
71
72
72
* Outer scope (S1) isolates `countAtom`.
73
-
* Inner scope (S2) isolates `nameAtom` and looks up the tree and finds `countAtom` in S1
73
+
* Inner scope (S2) isolates `nameAtom`, then looks up the tree and finds `countAtom` in S1.
74
74
75
75
---
76
76
77
77
**3 · Providing default values**
78
78
79
79
```tsx
80
80
<ScopeProvideratoms={[[countAtom, 42]]}>
81
-
<Counter /> {/* starts at 42 inside this scope, yay!*/}
81
+
<Counter /> {/* starts at 42 inside this scope */}
- Scope **S1** is the first scope under the store provider (**S0**). **S1** scopes **a**, so **a1** refers to the scoped **a** in **S1**.
117
-
-**c** is a derived atom. **c** reads **a** and **b**. In **S1**, **c** is not scoped so it reads **a1** and **b0** from **S1**.
118
-
-**c** is scoped in **S2**, so it reads **a** from **S2** and **b** from **S2**. This is because atom dependencies of scoped atoms are _implicitly scoped_.
119
-
- Outside **c** and **d** in **S2**, **a** and **b** still inherit from **S1**.
120
-
-**c** and **d** are both scoped in **S2**, so they both reads**a2** and **b2**. **c** and **d** share the same atom dependencies.**a2** in **c2** and **a2** in **d2** are the same atom.
116
+
- Scope **S1** is the first scope under the store provider (**S0**). **S1** scopes **a**, so **a1** refers to the scoped **a** in **S1**.
117
+
-**c** is a derived atom. **c** reads **a** and **b**. In **S1**, **c** is not scoped so it reads **a1** and **b0** from **S1**.
118
+
-**c** is scoped in **S2**, so it reads **a** from **S2** and **b** from **S2**. This is because atom dependencies of scoped atoms are _implicitly scoped_.
119
+
- Outside **c** and **d** in **S2**, **a** and **b** still inherit from **S1**.
120
+
-**c** and **d** are both scoped in **S2**, so they both read**a2**. Implicit dependencies are shared across scoped atoms in the same scope so**a2** in **c2** and **a2** in **d2** are the same atom.
0 commit comments