我实现与终极版的反应,我得到了相同名称的嵌套状态(见图片)具有相同名称
这里嵌套状态是我的减速器:
function helps(state = {
isFetching: false,
items: []
}, action) {
switch (action.type) {
case types.HELPS_FEED_REQUEST:
return Object.assign({}, state, {
isFetching: true
});
case types.HELPS_FEED_SUCCESS:
return Object.assign({}, state, {
isFetching: false,
items: [
...state.items,
...action.items
]
});
default:
return state;
}
}
const rootReducer = combineReducers({
helps
});
export default rootReducer;
index.js减速器:
import {combineReducers} from 'redux';
import help from './helpReducer';
import helps from './helpsReducer';
const rootReducer = combineReducers({
help,
helps
});
export default rootReducer;
我的问题是:为什么我不只有o ñ“帮助”状态与isFetching和项目?有什么明显的我失踪了?
编辑:
显然,这是因为我使用的减压器结合。所以,如果我改变函数的名称,例如helps_feed,国家将:
helps
-- helps_feed
为什么combineReducers使嵌套状态?
configureStore.js
import { createStore, applyMiddleware, compose } from 'redux';
import rootReducer from '../reducers';
import createSagaMiddleware, {END} from 'redux-saga';
import helpSagas from '../sagas/helpSaga';
export default function configureStore(initialState) {
const rootSagas = [
helpSagas
];
const sagaMiddleWare = createSagaMiddleware();
const store = createStore(
rootReducer,
initialState,
compose(
applyMiddleware(sagaMiddleWare),
window.devToolsExtension ? window.devToolsExtension() : f => f
));
store.runSaga = sagaMiddleWare.run(...rootSagas);
store.close =() => store.dispatch(END);
return store;
}
没有足够的信息来帮助你,你可以显示在其中创建该文件的商店? – QoP
@QoP我更新了我的问题。 –