还没有找到任何关于这个错误的东西:
“存储没有有效的缩减程序。确保传递给combineReducers的参数是一个值为reducers的对象。”
我的减速机
export default function FriendListReducer(state = {friends : []}, action) {
switch (action.type) {
case 'ADD_FRIEND':
return [
{ friends : action.payload.friend }, ...state.friends
]
default:
return state;
}
return state;
}
组合器
import { combineReducers } from 'redux';
import { FriendListReducer } from './FriendListReducer';
const rootReducer = combineReducers({
friends: FriendListReducer
});
export default rootReducer;
我的商店配置
import { applyMiddleware, createStore } from 'redux';
import thunkMiddleware from 'redux-thunk';
import createLogger from 'redux-logger';
import rootReducer from '../reducers/reducers';
export default function configureStore(initialState = { friends: [] }) {
const logger = createLogger({
collapsed: true,
predicate: () =>
process.env.NODE_ENV === `development`, // eslint-disable-line no-unused-vars
});
const middleware = applyMiddleware(thunkMiddleware, logger);
const store = middleware(createStore)(rootReducer, initialState);
if (module.hot) {
// Enable Webpack hot module replacement for reducers
module.hot.accept('../reducers/reducers', () => {
const nextRootReducer = require('../reducers/reducers').default;
store.replaceReducer(nextRootReducer);
});
}
return store;
}
9条答案
按热度按时间tjjdgumg1#
import
语句不正确。您可以将import { Foo } from 'bar'
与export Foo
一起使用,* 或者 * 如果使用export default Foo
导出,则使用import Foo from 'bar'
。换句话说,将
export default function FriendListReducer
更改为export function FriendListReducer
,或者将import语句从import { FriendListReducer }
更改为import FriendListReducer
。lg40wkob2#
如果对象为空。
此错误将显示。
ut6juiuv3#
../reducers/reducers?这名字很奇怪
不管怎样,似乎../reducers/reducers不返回一个reducer,如果reducers是一个目录,在里面放一个index.js,导入每个reducer并创建一个根reducer
**重要!!**您的州将有state.friendList。
我希望它能有所帮助
56lgkhnf4#
store.js
False
TRUE不使用{}
oug3syen5#
看起来你的顶级reducer函数使用数组作为默认值。Redux期望状态的最顶端是一个对象,而不是一个数组。尝试将数组放在该对象中的特定键处,如
{ friendList : [] }
。2hh7jdfx6#
在你的代码之上
而不是
import { FriendListReducer } from './FriendListReducer';
就说
import FriendListReducer from './FriendListReducer';
因为
FriendListReducer
是用export default FriendListReducer
导出的,而不是用export const FriendListReducer
导出的qlckcl4x7#
我遇到这个错误是因为错误的importimport {taskslice} from“./TaskSlice”;
正道
然后,我做了导入,比如import tasksSlice from“./TaskSlice”;
gk7wooem8#
2cmtqfgy9#
我也面临着这个问题。我所做的不是:
我说了:
而且成功了它需要存储区的有效对象。