0
私のapp.jsファイルに減速機を統合しようとしていますが、次のエラーが発生します。 反作用Redux:キャッチされていないエラー:関数。React Redux:未知のエラー:減速機が関数であると予想しました
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'
},
]
});
:リデューサー/ 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
})
に
"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;
}
メインapp.jsファイルをファイル
リデューサー/ booksReducers.js: のコードは以下のようになります。
私はどこが間違っているのか分かりません。誰でも私に何が間違っているかを教えてもらえますか?
おかげで、あなたのメインのapp.jsファイルで