为什么不链接调度Redux-Thunk

时间:2018-05-07 07:05:45

标签: reactjs redux redux-thunk react-thunk

为什么不链接调度Redux Thunk?只有第一次发货和第二次发货才能正常工作。

商店:

>>> kexec 2.0.16 Building

动作:

const store = createStore(reducers, loadState(), applyMiddleware(thunk));

修改 它奏效了:

export function doSomething(name) {
    return function (dispatch) {
        dispatch({
            type: 'USERNAME',
            payload: name
        })
        dispatch({
            type: 'OTHER_TYPE',
            payload: 'text'
        })

         return true;
    }
}

1 个答案:

答案 0 :(得分:2)

来自docs

    // We can dispatch both plain object actions and other thunks,
    // which lets us compose the asynchronous actions in a single flow.

    return dispatch(
      makeASandwichWithSecretSauce('My Grandma')
    ).then(() =>
      Promise.all([
        dispatch(makeASandwichWithSecretSauce('Me')),
        dispatch(makeASandwichWithSecretSauce('My wife'))
      ])
    ).then(() =>
      dispatch(makeASandwichWithSecretSauce('Our kids'))
    ).then(() =>
      dispatch(getState().myMoney > 42 ?
        withdrawMoney(42) :
        apologize('Me', 'The Sandwich Shop')
      )
    );
  

但我建议使用redux-saga而不是redux-thunk   因为these原因。