Reactjs Redux Thunk动作设置动作作为承诺

Reactjs Redux Thunk动作设置动作作为承诺,reactjs,typescript,redux,react-redux,redux-thunk,Reactjs,Typescript,Redux,React Redux,Redux Thunk,因此,我使用TS React、Redux和Thunk中间件来处理与api通信的Redux操作,但我似乎无法获得操作函数的初始配置 我的行动职能如下: export const startSession = ((accessCode: string) => { return async (dispatch: Dispatch): Promise<Action> => { try { const response = await apiCall(acc

因此,我使用TS React、Redux和Thunk中间件来处理与api通信的Redux操作,但我似乎无法获得操作函数的初始配置

我的行动职能如下:

export const startSession = ((accessCode: string) => {
return async (dispatch: Dispatch): Promise<Action> => {
    try {
        const response = await apiCall(accessCode);
        return dispatch({ type: SessionActions.START_SESSION, payload: response });
    } catch (e) {
        console.log('error', e)
     }
};
})

但两者似乎都不起作用。我原以为等待api响应会迫使redux等待,但它似乎将承诺返回到状态-如我的redux记录器所示:

 action undefined @ 19:10:17.807
 redux-logger.js?d665:1  prev state: {some state}
 redux-logger.js?d665:1  action:  Promise {<pending>}
我注意到这个分派类型是未定义的,所以在从api返回数据之前,必须先进行分派调用。如果有人能向我解释为什么会这样做,以及使用thunk编写动作的标准格式,那将非常有用

另外,如果有我丢失的信息,请告诉我

下面有人问我如何使用thunk初始化存储:

import { createStore, applyMiddleware } from 'redux';
import thunkMiddleware from 'redux-thunk';
import { createLogger } from 'redux-logger';
import { createBrowserHistory } from 'history';
import rootReducer from '../_reducers/index'
const loggerMiddleware = createLogger();
export const history = createBrowserHistory();

export const store = createStore(
    rootReducer,
    applyMiddleware(
        thunkMiddleware,
        loggerMiddleware
    )
);

你能用thunk中间件将代码粘贴到你初始化商店的地方吗?当然,我已经在上面添加了代码,你在哪里以及如何发送这个thunk?(另外,作为旁注:您应该切换到使用。它包括简化常见Redux用例的实用程序,为您处理所有存储设置,并且已经用TS编写)您可以将代码粘贴到使用thunk中间件初始化存储的位置吗?当然,我已经在上面添加了它,您将如何调度此thunk?(另外,作为旁注:您应该切换到使用。它包括简化常见Redux用例的实用程序,为您处理所有存储设置,并且已经用TS编写。)
Uncaught Error: Actions must be plain objects. Use custom middleware for async actions.
import { createStore, applyMiddleware } from 'redux';
import thunkMiddleware from 'redux-thunk';
import { createLogger } from 'redux-logger';
import { createBrowserHistory } from 'history';
import rootReducer from '../_reducers/index'
const loggerMiddleware = createLogger();
export const history = createBrowserHistory();

export const store = createStore(
    rootReducer,
    applyMiddleware(
        thunkMiddleware,
        loggerMiddleware
    )
);