我正在尝试构建一个应用程序,该应用程序有两个或更多个reducer“回答”我的storeState中的一个对象.
例:
storeState {
app: {...},
comments: [ ...two or more states inside one... ]
}
我已经尝试了以下使用不起作用的combineReducers,我的注释状态变成了一个空对象.
import { combineReducers } from 'redux';
import commentFacebookReducer from './twitch';
import commentYoutubeReducer from './reddit';
import appReducer from './app';
const rootReducer = combineReducers({
comments: [commentFacebookReducer, commentYoutubeReducer],
app: appReducer
});
export default rootReducer;
我已经尝试将我的评论缩减器组合在一起,然后将它们组合在rootReducer中:
import { combineReducers } from 'redux';
import commentFacebookReducer from './twitch';
import commentYoutubeReducer from './reddit';
import appReducer from './app';
const commentReducers = combineReducers({
commentFacebookReducer,
commentYoutubeReducer
});
const rootReducer = combineReducers({
comments: commentReducers,
app: appReducer
});
export default rootReducer;
但它给了我一个像以下那样的storeState.但我需要一个注释数组的状态,我不能处理这些减少名称(如commentFacebookReducer或commentYoutubeReducer),因为我会有数千个这样的减速器.
storeState {
app: {...},
comments: {
commentFacebookReducer: {...},
commentYoutubeReducer: {...}
}
}