Uncaught TypeError:无法读取化简器中未定义的属性“ then”

时间:2018-07-31 18:13:32

标签: redux promise

我在此代码上收到错误Uncaught TypeError: Cannot read property 'then' of undefined。我已经查看了其他解决方案,但这些解决方案似乎不适用于我的情况。第一次调度将按预期进行,但从不进行第二次调度(接受)。

export function save() {
    return (dispatch, getState) => {
        return (
            dispatch(update())
        .then (() =>
            dispatch(accept())
        )
        );
    };
}

1 个答案:

答案 0 :(得分:1)

默认情况下,dispatch()返回您传递的所有操作。

如果您使用redux-thunk中间件并分派thunk函数,则dispatch()将返回thunk函数返回的内容。

因此,该代码仅在update是thunk的情况下才有效,并且它返回一个promise。

相关问题