Skip to content

Latest commit

 

History

History
7 lines (4 loc) · 713 Bytes

6-7.Redux的三个Store方法.md

File metadata and controls

7 lines (4 loc) · 713 Bytes

store的三个方法

  1. getState() retrieves the current state of the Redux store. If we ran console.log(store.getState()) with the code above, we could get 0 since it is the initial state of our application.

  2. dispatch() is the most commonly used. It is how we dispatch actions to change the state of the application. If we run store.dispatch( { type: 'INCREMENT' }); followed by console.log(store.getState()); we will get 1, which reflects the current state resulting from the INCREMENT action.

  3. subscribe() registers a callback that the redux store will call any time an action has been dispatched so you can update the UI of your application to reflect the current application state.