in your web browser.
189 |
190 | You can also try them in codesandbox.io:
191 | [01](https://codesandbox.io/s/github/dai-shi/react-hooks-global-state/tree/main/examples/01\_minimal)
192 | [02](https://codesandbox.io/s/github/dai-shi/react-hooks-global-state/tree/main/examples/02\_typescript)
193 | [03](https://codesandbox.io/s/github/dai-shi/react-hooks-global-state/tree/main/examples/03\_actions)
194 | [04](https://codesandbox.io/s/github/dai-shi/react-hooks-global-state/tree/main/examples/04\_fetch)
195 | [05](https://codesandbox.io/s/github/dai-shi/react-hooks-global-state/tree/main/examples/05\_onmount)
196 | [06](https://codesandbox.io/s/github/dai-shi/react-hooks-global-state/tree/main/examples/06\_reducer)
197 | [07](https://codesandbox.io/s/github/dai-shi/react-hooks-global-state/tree/main/examples/07\_middleware)
198 | [08](https://codesandbox.io/s/github/dai-shi/react-hooks-global-state/tree/main/examples/08\_thunk)
199 | [09](https://codesandbox.io/s/github/dai-shi/react-hooks-global-state/tree/main/examples/09\_comparison)
200 | [10](https://codesandbox.io/s/github/dai-shi/react-hooks-global-state/tree/main/examples/10\_immer)
201 | [11](https://codesandbox.io/s/github/dai-shi/react-hooks-global-state/tree/main/examples/11\_deep)
202 | [13](https://codesandbox.io/s/github/dai-shi/react-hooks-global-state/tree/main/examples/13\_persistence)
203 |
204 | ## Blogs
205 |
206 | * [TypeScript-aware React hooks for global state](https://blog.axlight.com/posts/typescript-aware-react-hooks-for-global-state/)
207 | * [An alternative to React Redux by React Hooks API (For both JavaScript and TypeScript)](https://blog.axlight.com/posts/an-alternative-to-react-redux-by-react-hooks-api-for-both-javascript-and-typescript/)
208 | * [Redux middleware compatible React Hooks library for easy global state management](https://blog.axlight.com/posts/redux-middleware-compatible-react-hooks-library-for-easy-global-state-management/)
209 | * [React Hooks Tutorial on pure useReducer + useContext for global state like Redux and comparison with react-hooks-global-state](https://blog.axlight.com/posts/react-hooks-tutorial-for-pure-usereducer-usecontext-for-global-state-like-redux-and-comparison/)
210 | * [Four patterns for global state with React hooks: Context or Redux](https://blog.axlight.com/posts/four-patterns-for-global-state-with-react-hooks-context-or-redux/)
211 | * [Steps to Develop Global State for React With Hooks Without Context](https://blog.axlight.com/posts/steps-to-develop-global-state-for-react/)
212 |
213 | ## Community Wiki
214 |
215 | * [Persistence](https://github.com/dai-shi/react-hooks-global-state/wiki/Persistence)
216 | * [Optional initialState](https://github.com/dai-shi/react-hooks-global-state/wiki/Optional-initialState)
217 |
--------------------------------------------------------------------------------
/__tests__/e2e/__snapshots__/08_thunk.ts.snap:
--------------------------------------------------------------------------------
1 | // Jest Snapshot v1, https://goo.gl/fbAQLP
2 |
3 | exports[`08_thunk should work with events 1`] = `
4 | "
5 | Counter Count: 1 +1 -1
Count: 1 +1 -1
Person
6 |
7 |
8 | "
9 | `;
10 |
11 | exports[`08_thunk should work with events 2`] = `
12 | "
13 | Counter Count: 0 +1 -1
Count: 0 +1 -1
Person
14 |
15 |
16 | "
17 | `;
18 |
19 | exports[`08_thunk should work with events 3`] = `
20 | "
21 | Counter Count: 1 +1 -1
Count: 1 +1 -1
Person
22 |
23 |
24 | "
25 | `;
26 |
27 | exports[`08_thunk should work with events 4`] = `
28 | "
29 | Counter Count: 0 +1 -1
Count: 0 +1 -1
Person
30 |
31 |
32 | "
33 | `;
34 |
35 | exports[`08_thunk should work with events 5`] = `
36 | "
37 | Counter Count: 0 +1 -1
Count: 0 +1 -1
Person
38 |
39 |
40 | "
41 | `;
42 |
43 | exports[`08_thunk should work with events 6`] = `
44 | "
45 | Counter Count: 0 +1 -1
Count: 0 +1 -1
Person
46 |
47 |
48 | "
49 | `;
50 |
51 | exports[`08_thunk should work with events 7`] = `
52 | "
53 | Counter Count: 0 +1 -1
Count: 0 +1 -1
Person
54 |
55 |
56 | "
57 | `;
58 |
59 | exports[`08_thunk should work with events 8`] = `
60 | "
61 | Counter Count: 0 +1 -1
Count: 0 +1 -1
Person
62 |
63 |
64 | "
65 | `;
66 |
67 | exports[`08_thunk should work with events 9`] = `
68 | "
69 | Counter Count: 0 +1 -1
Count: 0 +1 -1
Person
70 |
71 |
72 | "
73 | `;
74 |
75 | exports[`08_thunk should work with events 10`] = `
76 | "
77 | Counter Count: 0 +1 -1
Count: 0 +1 -1
Person
78 |
79 |
80 | "
81 | `;
82 |
83 | exports[`08_thunk should work with events 11`] = `
84 | "
85 | Counter Count: 0 +1 -1
Count: 0 +1 -1
Person
86 |
87 |
88 | "
89 | `;
90 |
91 | exports[`08_thunk should work with events 12`] = `
92 | "
93 | Counter Count: 0 +1 -1
Count: 0 +1 -1
Person
94 |
95 |
96 | "
97 | `;
98 |
--------------------------------------------------------------------------------
/__tests__/e2e/__snapshots__/11_deep.ts.snap:
--------------------------------------------------------------------------------
1 | // Jest Snapshot v1, https://goo.gl/fbAQLP
2 |
3 | exports[`11_deep should work with events 1`] = `
4 | "
5 |
6 |
7 |
8 | "
9 | `;
10 |
11 | exports[`11_deep should work with events 2`] = `
12 | "
13 |
14 |
15 |
16 | "
17 | `;
18 |
19 | exports[`11_deep should work with events 3`] = `
20 | "
21 |
22 |
23 |
24 | "
25 | `;
26 |
27 | exports[`11_deep should work with events 4`] = `
28 | "
29 |
30 |
31 |
32 | "
33 | `;
34 |
35 | exports[`11_deep should work with events 5`] = `
36 | "
37 |
38 |
39 |
40 | "
41 | `;
42 |
43 | exports[`11_deep should work with events 6`] = `
44 | "
45 |
46 |
47 |
48 | "
49 | `;
50 |
51 | exports[`11_deep should work with events 7`] = `
52 | "
53 |
54 |
55 |
56 | "
57 | `;
58 |
59 | exports[`11_deep should work with events 8`] = `
60 | "
61 |
62 |
63 |
64 | "
65 | `;
66 |
67 | exports[`11_deep should work with events 9`] = `
68 | "
69 |
70 |
71 |
72 | "
73 | `;
74 |
75 | exports[`11_deep should work with events 10`] = `
76 | "
77 |
78 |
79 |
80 | "
81 | `;
82 |
--------------------------------------------------------------------------------
/__tests__/e2e/__snapshots__/09_comparison.ts.snap:
--------------------------------------------------------------------------------
1 | // Jest Snapshot v1, https://goo.gl/fbAQLP
2 |
3 | exports[`09_comparison should work with events 1`] = `
4 | "
5 | useReducer + useContext Counter Count: 1 +1 -1 (numRendered: 6)
Count: 1 +1 -1 (numRendered: 8)
Person react-hooks-global-state Counter Count: 0 +1 -1 (numRendered: 2)
Count: 0 +1 -1 (numRendered: 4)
Person
6 |
7 |
8 | "
9 | `;
10 |
11 | exports[`09_comparison should work with events 2`] = `
12 | "
13 | useReducer + useContext Counter Count: 0 +1 -1 (numRendered: 10)
Count: 0 +1 -1 (numRendered: 12)
Person react-hooks-global-state Counter Count: 0 +1 -1 (numRendered: 2)
Count: 0 +1 -1 (numRendered: 4)
Person
14 |
15 |
16 | "
17 | `;
18 |
19 | exports[`09_comparison should work with events 3`] = `
20 | "
21 | useReducer + useContext Counter Count: 1 +1 -1 (numRendered: 14)
Count: 1 +1 -1 (numRendered: 16)
Person react-hooks-global-state Counter Count: 0 +1 -1 (numRendered: 2)
Count: 0 +1 -1 (numRendered: 4)
Person
22 |
23 |
24 | "
25 | `;
26 |
27 | exports[`09_comparison should work with events 4`] = `
28 | "
29 | useReducer + useContext Counter Count: 0 +1 -1 (numRendered: 18)
Count: 0 +1 -1 (numRendered: 20)
Person react-hooks-global-state Counter Count: 0 +1 -1 (numRendered: 2)
Count: 0 +1 -1 (numRendered: 4)
Person
30 |
31 |
32 | "
33 | `;
34 |
35 | exports[`09_comparison should work with events 5`] = `
36 | "
37 | useReducer + useContext Counter Count: 0 +1 -1 (numRendered: 22)
Count: 0 +1 -1 (numRendered: 24)
Person react-hooks-global-state Counter Count: 0 +1 -1 (numRendered: 2)
Count: 0 +1 -1 (numRendered: 4)
Person
38 |
39 |
40 | "
41 | `;
42 |
43 | exports[`09_comparison should work with events 6`] = `
44 | "
45 | useReducer + useContext Counter Count: 0 +1 -1 (numRendered: 26)
Count: 0 +1 -1 (numRendered: 28)
Person react-hooks-global-state Counter Count: 0 +1 -1 (numRendered: 2)
Count: 0 +1 -1 (numRendered: 4)
Person
46 |
47 |
48 | "
49 | `;
50 |
51 | exports[`09_comparison should work with events 7`] = `
52 | "
53 | useReducer + useContext Counter Count: 0 +1 -1 (numRendered: 30)
Count: 0 +1 -1 (numRendered: 32)
Person react-hooks-global-state Counter Count: 0 +1 -1 (numRendered: 2)
Count: 0 +1 -1 (numRendered: 4)
Person
54 |
55 |
56 | "
57 | `;
58 |
59 | exports[`09_comparison should work with events 8`] = `
60 | "
61 | useReducer + useContext Counter Count: 0 +1 -1 (numRendered: 34)
Count: 0 +1 -1 (numRendered: 36)
Person react-hooks-global-state Counter Count: 0 +1 -1 (numRendered: 2)
Count: 0 +1 -1 (numRendered: 4)
Person
62 |
63 |
64 | "
65 | `;
66 |
67 | exports[`09_comparison should work with events 9`] = `
68 | "
69 | useReducer + useContext Counter Count: 0 +1 -1 (numRendered: 38)
Count: 0 +1 -1 (numRendered: 40)
Person react-hooks-global-state Counter Count: 0 +1 -1 (numRendered: 2)
Count: 0 +1 -1 (numRendered: 4)
Person
70 |
71 |
72 | "
73 | `;
74 |
75 | exports[`09_comparison should work with events 10`] = `
76 | "
77 | useReducer + useContext Counter Count: 0 +1 -1 (numRendered: 42)
Count: 0 +1 -1 (numRendered: 44)
Person react-hooks-global-state Counter Count: 0 +1 -1 (numRendered: 2)
Count: 0 +1 -1 (numRendered: 4)
Person
78 |
79 |
80 | "
81 | `;
82 |
83 | exports[`09_comparison should work with events 11`] = `
84 | "
85 | useReducer + useContext Counter Count: 0 +1 -1 (numRendered: 42)
Count: 0 +1 -1 (numRendered: 44)
Person react-hooks-global-state Counter Count: 1 +1 -1 (numRendered: 6)
Count: 1 +1 -1 (numRendered: 8)
Person
86 |
87 |
88 | "
89 | `;
90 |
91 | exports[`09_comparison should work with events 12`] = `
92 | "
93 | useReducer + useContext Counter Count: 0 +1 -1 (numRendered: 42)
Count: 0 +1 -1 (numRendered: 44)
Person react-hooks-global-state Counter Count: 0 +1 -1 (numRendered: 10)
Count: 0 +1 -1 (numRendered: 12)
Person
94 |
95 |
96 | "
97 | `;
98 |
99 | exports[`09_comparison should work with events 13`] = `
100 | "
101 | useReducer + useContext Counter Count: 0 +1 -1 (numRendered: 42)
Count: 0 +1 -1 (numRendered: 44)
Person react-hooks-global-state Counter Count: 1 +1 -1 (numRendered: 14)
Count: 1 +1 -1 (numRendered: 16)
Person
102 |
103 |
104 | "
105 | `;
106 |
107 | exports[`09_comparison should work with events 14`] = `
108 | "
109 | useReducer + useContext Counter Count: 0 +1 -1 (numRendered: 42)
Count: 0 +1 -1 (numRendered: 44)
Person react-hooks-global-state Counter Count: 0 +1 -1 (numRendered: 18)
Count: 0 +1 -1 (numRendered: 20)
Person
110 |
111 |
112 | "
113 | `;
114 |
115 | exports[`09_comparison should work with events 15`] = `
116 | "
117 | useReducer + useContext Counter Count: 0 +1 -1 (numRendered: 42)
Count: 0 +1 -1 (numRendered: 44)
Person react-hooks-global-state Counter Count: 0 +1 -1 (numRendered: 18)
Count: 0 +1 -1 (numRendered: 20)
Person
118 |
119 |
120 | "
121 | `;
122 |
123 | exports[`09_comparison should work with events 16`] = `
124 | "
125 | useReducer + useContext Counter Count: 0 +1 -1 (numRendered: 42)
Count: 0 +1 -1 (numRendered: 44)
Person react-hooks-global-state Counter Count: 0 +1 -1 (numRendered: 18)
Count: 0 +1 -1 (numRendered: 20)
Person
126 |
127 |
128 | "
129 | `;
130 |
131 | exports[`09_comparison should work with events 17`] = `
132 | "
133 | useReducer + useContext Counter Count: 0 +1 -1 (numRendered: 42)
Count: 0 +1 -1 (numRendered: 44)
Person react-hooks-global-state Counter Count: 0 +1 -1 (numRendered: 18)
Count: 0 +1 -1 (numRendered: 20)
Person
134 |
135 |
136 | "
137 | `;
138 |
139 | exports[`09_comparison should work with events 18`] = `
140 | "
141 | useReducer + useContext Counter Count: 0 +1 -1 (numRendered: 42)
Count: 0 +1 -1 (numRendered: 44)
Person react-hooks-global-state Counter Count: 0 +1 -1 (numRendered: 18)
Count: 0 +1 -1 (numRendered: 20)
Person
142 |
143 |
144 | "
145 | `;
146 |
147 | exports[`09_comparison should work with events 19`] = `
148 | "
149 | useReducer + useContext Counter Count: 0 +1 -1 (numRendered: 42)
Count: 0 +1 -1 (numRendered: 44)
Person react-hooks-global-state Counter Count: 0 +1 -1 (numRendered: 18)
Count: 0 +1 -1 (numRendered: 20)
Person
150 |
151 |
152 | "
153 | `;
154 |
155 | exports[`09_comparison should work with events 20`] = `
156 | "
157 | useReducer + useContext Counter Count: 0 +1 -1 (numRendered: 42)
Count: 0 +1 -1 (numRendered: 44)
Person react-hooks-global-state Counter Count: 0 +1 -1 (numRendered: 18)
Count: 0 +1 -1 (numRendered: 20)
Person
158 |
159 |
160 | "
161 | `;
162 |
--------------------------------------------------------------------------------