Reactjs React Redux:未捕获错误:预期减速器是一个函数
我正在尝试在app.js文件中集成减缩器,但不断出现以下错误: React-Redux:未捕获错误:预期减速器是一个函数。 代码如下所示: reducers/booksReducers.js文件Reactjs React Redux:未捕获错误:预期减速器是一个函数,reactjs,redux,Reactjs,Redux,我正在尝试在app.js文件中集成减缩器,但不断出现以下错误: React-Redux:未捕获错误:预期减速器是一个函数。 代码如下所示: reducers/booksReducers.js文件 "use strict" export function booksReducers(state={ books: [] }, action) { switch (action.type) { case 'POST_BOOK': // let books = state.bo
"use strict"
export function booksReducers(state={ books: [] }, action) {
switch (action.type) {
case 'POST_BOOK':
// let books = state.books.concat(action.payload);
// return {books};
return { books: [...state.books, ...action.payload] }
break;
default:
break;
}
return state;
}
reducers/index.js文件
"use strict"
import { combineReducers } from 'redux';
// HERE IMPORT REDUCERS TO BE COMBINED
import { booksReducers } from './booksReducers';
//HERE COMBINE THE REDUCERS
export default combineReducers({
books: booksReducers
})
主app.js文件:
import { createStore } from 'redux';
import { reducers } from './reducers/index';
const store = createStore(reducers);
store.subscribe(() => {
console.log('current state is ', store.getState());
});
store.dispatch({
type: 'POST_BOOK',
payload: [
{
id: 1,
title: 'Book Title',
description: 'Book Description'
},
{
id: 2,
title: 'Second Book Title',
description: 'Second Book Description'
},
]
});
我不确定我错在哪里。有人能告诉我这里出了什么问题吗
谢谢在主app.js文件中,替换
从'./reducers/index'导入{reducers}代码>
与
从“./reducers/index”导入减缩器代码>
与redcuers/index.js一样,combinereducer
作为默认值导出。所以,您不需要{}