我正在try 为不同的react 成分创建单独的减速器.代码是这样的:
Store.tsx:
const store = createStore(rootReducer, composeWithDevTools());
Root.Reducers.tsx:
import { combineReducers } from 'redux';
import mainReducer from './main.reducers';
import profileReducers from './components/Profile/Profile.reducers';
const rootReducer = combineReducers({
mainReducer,
profileReducers,
});
export default rootReducer;
Main.Reducers.tsx:
<...>
function mainReducer(state = initialState, action: AnyAction) {
switch (action.type) {
case HOME_PAGE_MOVIES_ADDED:
return {
...state,
homePageMovies: action.homePageMovies,
};
case MOVIE_SELECTED:
return {
...state,
selectedMovie: action.selectedMovie,
};
default:
return state;
export default mainReducer;
export type RootState = ReturnType<typeof mainReducer>;
Profile.Reducers.tsx:
interface mainState {
selectedCategory: boolean;
}
const initialState: mainState = {
selectedCategory: false,
};
function profileReducers(state = initialState, action: AnyAction) {
switch (action.type) {
case CATEGORY_SELECTED:
return {
...state,
selectedCategory: action.selectedCategory,
};
default:
return state;
}
}
export default profileReducers;
export type RootState = ReturnType<typeof profileReducers>;
When I try to render UI, I get following error:
一旦我在*/store.tsx
>;const store = createStore(mainReducer, composeWithDevTools());
用rootReducer
替换mainReducer
,我就会得到这个错误.
我遗漏了什么?谢谢!