Skip to content

Commit fdce20c

Browse files
authored
Removed section about calling hooks inside actions
Unfortunately you can't use hooks inside actions because of how React works. This thing should be implemented
1 parent 387848d commit fdce20c

File tree

1 file changed

+0
-30
lines changed

1 file changed

+0
-30
lines changed

README.MD

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -247,36 +247,6 @@ const result = store.addTodo('buy milk')
247247
await store.getTodos()
248248
```
249249

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-
```
280250
</p></details>
281251

282252
### TODO:

0 commit comments

Comments
 (0)