0
我想在我的app.js文件中集成減速器,但我不斷收到以下錯誤: React Redux:Uncaught錯誤:期望減速器是一個功能。 代碼如下所示:React Redux:Uncaught錯誤:期望減速器是一個函數
的減速/ booksReducers.js文件
"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;
}
的減速/ 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'
},
]
});
我不知道,我哪裏出錯了。有誰能讓我知道這裏有什麼問題嗎?
感謝