Where to dispatch multiple actions in redux?

前端 未结 7 1739
终归单人心
终归单人心 2021-01-31 08:10

I am using redux with connect and redux-thunk middleware and containers.

Currently when an user perform an action, example one click on a butto

7条回答
  •  忘掉有多难
    2021-01-31 08:51

    The easiest way is to use a specialized middleware redux-soldier:

    import { createStore, applyMiddleware } from 'redux'
    import { reduxSoldierMiddleware } from 'redux-soldier'
    
    const store = createStore(rootReducer, applyMiddleware(reduxSoldierMiddleware))
    store.dispatch([
      {type: 'INCREMENT'}, // traditional action
      addTodo('Start using redux-soldier'), // action creator
      fetchUser(), // thunk action
    ])
    

    redux-soldier is also a full replacement for redux-thunk

    For more info check the documentation redux-soldier.

提交回复
热议问题