![](/img/trans.png)
[英]Redux toolkit combineReducers problem.:Store does not have a valid reducer. Make sure the argument passed to combineReducers is an object whose
[英]Store does not have a valid reducer. react redux
我遇到上面的問題,我嘗試了一下 ,但是沒有運氣。
這是我的商店:
import { compose, combineReducers, applyMiddleware, createStore } from "redux";
import thunkMiddleware from "redux-thunk";
import * as activities from "../reducers/activities";
import * as location from "../reducers/location";
const configureStore = railsProps => {
const composedStore = compose(
applyMiddleware(thunkMiddleware),
window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
);
const combinedReducers = combineReducers({
location,
activities
});
return composedStore(createStore)(combinedReducers, railsProps);
};
export default configureStore;
這是我的位置減少器:
import { combineReducers } from "redux";
import * as actions from "../constants/constants";
const coordinates = (state = {}, action) => {
switch (action.type) {
case actions.GET_LOCATION_SUCCESS:
case actions.GET_LOCATION_REQUEST:
case actions.GET_LOCATION_FAILURE:
default:
return state;
}
};
const reducer = coordinates;
export default reducer;
這是我的活動減少器:
import { combineReducers } from "redux";
import * as actions from "../constants/constants";
const page = (state = 0, action) => {
switch (action.type) {
case actions.NEXT_ACTIVITY_PAGE:
return action.page < action.totalPages - 1
? action.page + 1
: action.page;
case actions.PREV_ACTIVITY_PAGE:
return action.page > 0 ? action.page - 1 : 0;
default:
return state;
}
};
const activities = (state = {}, action) => {
switch (action.type) {
case actions.FETCH_ACTIVITIES_SUCCESS: {
return state.concat(action.activities);
}
case actions.FETCH_ACTIVITIES_REQUEST:
case actions.FETCH_ACTIVITIES_FAILURE:
default:
return state;
}
};
const reducer = combineReducers({ page, activities });
export default reducer;
我想這與CombineReducers方法以及我如何導入東西有關,但是我不確定那里出了什么問題。
謝謝
這是錯誤的:
import * as activities from "../reducers/activities";
import * as location from "../reducers/location";
上面的命令將從文件中導出所有命名的導出,而reducer是默認導出。
正確:
import activities from "../reducers/activities";
import location from "../reducers/location";
編輯:
如果要從文件中導出化徑器,請將其命名為:
export const page = (state = 0, action) => {
switch (action.type) {
...
}
};
export const activities = (state = {}, action) => {
switch (action.type) {
...
}
};
然后:
import { page, activities } from 'path/to/file.js';
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.