Redux-thunk不调度动作

时间:2017-05-16 10:51:36

标签: redux jsx redux-thunk

按下按钮时,我想要发送一对Redux动作。其中一个应该采用服务列表并对其执行reducer逻辑,另一个应该只是在reducer中触发一些逻辑:

function retrieveServices(services) {
    return {
        type: RETRIEVE_SERVICES,
        services,
    };
}

function toggleSubmitState() {
    return {
        type: TOGGLE_SUBMIT_STATE,
    };
}

我有以下行动,我认为可以解决这个问题:

export function submitGameplan(services) {
    return (dispatch => {
        dispatch(toggleSubmitState());
        dispatch(retrieveServices(services));
    };
}

这就是我在我的组件中调用它的方式:

    const { submitter, dispatch, services } = this.props;

    const submitWithServices = () => {
        dispatch(submitter(services));
    };

    return (
      <div>

        <button onClick={submitWithServices}>
            <div>Submit</div>
        </button>

      </div>
    );

传入的submitter操作为submitGameplan

尽管redux-thunk似乎正在采取行动并解雇它(我得到了console.log输出),但它没有调度行动。

除了(我可能)在我的行动中错误调用该函数的可能性之外,也许在我的主要应用程序级组件中已经完成了这个事实:

const boundActions = bindActionCreators(actions, dispatch);

然后将所有操作传递为boundActions,即我的组件将获得boundActions.submitGameplan

但是,我不确定为什么这个动作不会按照书面形式发送这两个动作中的任何一个。

1 个答案:

答案 0 :(得分:1)

事实证明,这在重新编译之后起作用,不知道为什么它之前没有用。