File tree Expand file tree Collapse file tree 1 file changed +0
-30
lines changed Expand file tree Collapse file tree 1 file changed +0
-30
lines changed Original file line number Diff line number Diff line change @@ -247,36 +247,6 @@ const result = store.addTodo('buy milk')
247
247
await store .getTodos ()
248
248
```
249
249
250
- Actions of one store may call other actions from other stores. It is possible because ** all** React hooks work inside actions.
251
-
252
-
253
- ``` tsx
254
- const [todoContext, Provider] = createStoreContext ({todos: []}, {
255
- addTodo : ({state , setState }, todo ) => {
256
- setState ({todos: [... state .todos , todo ]})
257
- },
258
- })
259
-
260
- const [mainContext, Provider] = createStoreContext ({message: ' ' }, {
261
- someAction : ({setState }, name ) => {
262
- const todoStore = React .useContext (todoContext )
263
- const newMessage = ` Hello, ${name }, you have ${todoStore .todos .length } todos! `
264
- setState ({message: newMessage })
265
- },
266
- })
267
-
268
- ...
269
-
270
- // Usage
271
- const todoStore = React .useContext (todoContext )
272
- const mainStore = React .useContext (mainContext )
273
-
274
- todoStore .addTodo (' buy milk' )
275
- todoStore .addTodo (' learn typescript' )
276
-
277
- mainStore .someAction (' Dmitrijs' )
278
- // mainStore.message is "Hello, Dmitrijs, you have 2 todos!"
279
- ```
280
250
</p ></details >
281
251
282
252
### TODO:
You can’t perform that action at this time.
0 commit comments