Commit 6f2de4e
authored
fix: change useStateStore to use useSyncExternalStore (#2573)
### 🎯 Goal
Changing stores on the fly would keep previously calculated state for a
bit before the effect would run to recalculate it - using
`useSyncExternalStore` (thank you, @myandrienko) should alleviate this
issue. Both `subscribe` and `getSnapshot` functions required by the
React hook are wrapped to allow for selector functionality,
[`geSnapshot` requires the output to be
cached](https://react.dev/reference/react/useSyncExternalStore#parameters)
so the wrapper reuses similar cache check mechanism as
`subscribeWithSelector` does internally.1 parent e81fc69 commit 6f2de4e
1 file changed
+43
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
5 | 9 | | |
6 | 10 | | |
7 | 11 | | |
| |||
14 | 18 | | |
15 | 19 | | |
16 | 20 | | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
21 | 36 | | |
22 | | - | |
23 | | - | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
24 | 41 | | |
25 | | - | |
| 42 | + | |
26 | 43 | | |
27 | | - | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
28 | 60 | | |
29 | 61 | | |
| 62 | + | |
| 63 | + | |
30 | 64 | | |
31 | 65 | | |
0 commit comments