我已经花了几个小时试图弄清这个错误,并尝试对似乎重复的问题提出建议,但是我无法解决。我认为我的商店配置可能有问题,但是我无法正常使用...
我无法使用异步操作,并且总是收到此错误:错误:操作必须是普通对象。使用自定义中间件执行异步操作。
我的减速器:
import { ADD_REPOS, CLEAR_REPOS } from '../actions/types';
const repos = (state = [], action) => {
switch (action.type) {
case ADD_REPOS:
return action.repos;
case CLEAR_REPOS:
return [];
default:
return state;
}
};
export default repos
我的操作(getRepos仅是一个测试函数。我想创建异步操作以进行API调用)。
import { ADD_REPOS, CLEAR_REPOS } from './types';
export const addRepos = repos => ({
type: ADD_REPOS,
repos,
});
export const clearRepos = () => ({ type: CLEAR_REPOS });
export function getRepos() {
return function (dispatch) {
setTimeout(function () {
dispatch(addRepos({"Example1": "example1", "Example2": "example2"}));
}, 1000);
}
}
我的商店配置:
import { applyMiddleware, createStore } from 'redux';
import rootReducer from './reducers/index';
import thunk from 'redux-thunk';
export default function configureStore(initialState = {}) {
const store = createStore(rootReducer, initialState, applyMiddleware(thunk));
return store;
}
我的依赖项:
"@expo/samples": "2.1.1",
"axios": "^0.18.0",
"expo": "^32.0.0",
"react": "16.5.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz",
"react-native-axios": "^0.17.1",
"react-native-elements": "^1.1.0",
"react-navigation": "^3.0.9",
"react-redux": "6.0.0",
"redux": "^4.0.1",
"redux-devtools-extension": "^2.13.8",
"redux-logger": "^3.0.6",
"redux-thunk": "^2.3.0"
有人知道我在这里缺少什么吗?