
上QQ阅读APP看书,第一时间看更新
Dispatching actions
Now, there is only one thing left to do—dispatching actions to the store. You can simply pass action objects to the store.dispatch() function:
store.dispatch({ type: 'CREATE_POST', user: 'dan', text: 'hello world' })
However, it is best practice to use action creators instead, as follows:
store.dispatch(createPost('dan', 'hello world'))
Dispatching an action will result in the state being changed (by executing the reducer), and thus, the subscribed function being called:

Output of our subscribed function, after dispatching the createPost action
We can now dispatch any actions we want, have the state change accordingly, and then get notified about the new state.