商店没有有效的减速器。反应减少
我有上面的问题,我试过this,但没有运气。商店没有有效的减速器。反应减少
这里是我的店:
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";
以上将出口从文件中的所有命名的出口。
正确:
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';
在我的活动文件中我有一个'page'和一个'activities' reducer这是否意味着我应该将它们全部放在单独的文件中? –
如果你觉得在单独的文件中管理它们会更好,那就去做吧。 – Tomasz
但我该怎么做,否则,当我只能有一个'导出默认'每个文件,并需要导出'页面和活动'? –
从http://redux.js.org/docs/api/combineReducers.html也许你应该将'import *'替换为“../ redurs/location”的位置;''用'import location from“../reducers/位置“;'(在'arguments'部分下的链接关于该导入语句的页面中有一个注释)。 –