Javascript 调用函数并在函数中使用Redux Thunk分派操作
我有两个函数: 一个调用第二个函数并分派操作:Javascript 调用函数并在函数中使用Redux Thunk分派操作,javascript,reactjs,redux,react-redux,redux-thunk,Javascript,Reactjs,Redux,React Redux,Redux Thunk,我有两个函数: 一个调用第二个函数并分派操作: export function fetchAppClasses() { return function (dispatch) { return axios.get(config.apiUrl + '/sdwan/appClasses', axcfg) .then(function (response) { updateAfterInitialFetch(response); dispa
export function fetchAppClasses() {
return function (dispatch) {
return axios.get(config.apiUrl + '/sdwan/appClasses', axcfg)
.then(function (response) {
updateAfterInitialFetch(response);
dispatch(fetchAppClassesSuccess(response));
})
}
}
在上述函数中调用的第二个函数:
export function updateSelectionAppClassIds(appClasses) {
// do some stuff
}
但当我执行此操作(调用函数并分派操作)时,浏览器会显示以下错误:
错误:ReferenceError:未定义分派
如果我从第一个函数中删除函数updateSelectionAppClassID调用,并让分派为,则不会给出该错误
如何使用Thunk调用任何函数以及同一函数中的分派和操作
这是我的配置存储:
import {createStore, compose, applyMiddleware} from 'redux';
import reduxImmutableStateInvariant from 'redux-immutable-state-invariant';
import rootReducer from '../reducers';
import thunk from 'redux-thunk';
export default function configureStore(initialState) {
const middlewares = [
// Add other middleware on this line...
reduxImmutableStateInvariant(),
thunk
];
return createStore(rootReducer, initialState,
applyMiddleware(...middlewares)
);
}
我只能在thunk函数中调度,如果我做了任何其他操作,就会出现错误。发布您的
configureStore
代码,似乎您没有正确设置中间件,因为您的thunk设置正确您是否在更新选择AppClassID
中使用dispatch
?是的,我是。有另一个消息。