我是Redux的新手,并遵循了有关在React中实现Redux的教程。我遇到一个问题,似乎是从store.js的createStore函数在app.js中接收不到任何值的。有什么想法吗?
app.js
import React, { Component } from 'react';
import AppNavbar from './components/AppNavbar';
import ShoppingList from './components/ShoppingList';
import ItemModal from './components/ItemModal';
import { Container } from 'reactstrap';
import { Provider } from 'react-redux';
import store from './store';
import 'bootstrap/dist/css/bootstrap.min.css';
import './App.css';
class App extends Component {
render() {
return (
<Provider store={store}>
<div className="App">
<AppNavbar />
<Container>
<ItemModal />
<ShoppingList />
</Container>
</div>
</Provider>
);
}
}
export default App;
store.js
import { createStore, applyMiddleware, compose } from 'redux';
import thunk from 'redux-thunk';
import rootReducer from './reducers';
const initialState = {};
const middleware = [thunk];
const store = createStore(
rootReducer,
initialState,
compose(
applyMiddleware(thunk)
)
);
导出默认存储;
reducers文件夹 itemReducer.js-仅显示GET_ITEMS案例
import {
GET_ITEMS,
ADD_ITEM,
DELETE_ITEM,
ITEMS_LOADING
} from '../actions/types';
const initialState = {
items: [],
loading: false
};
export default function(state = initialState, action) {
switch (action.type) {
case GET_ITEMS:
return {
...state,
items: action.payload,
loading: false
};
index.js
import { combineReducers } from 'redux';
import itemReducer from './itemReducer';
export default combineReducers({
item: itemReducer
});
错误:
TypeError:无法读取未定义的属性“ apply” (匿名功能) C://client/node_modules/redux/es/redux.js:523
return funcs.reduce(function (a, b) {
return function () {
return a(b.apply(undefined, arguments));
};
});
}
createStore C://client/node_modules/redux/es/redux.js:87
throw new Error('Expected the enhancer to be a function.');
}
return enhancer(createStore)(reducer, preloadedState);
}
if (typeof reducer !== 'function') {
./ src / store.js C://client/src/store.js:9
const middleware = [thunk];
const store = createStore(
rootReducer,
initialState,
compose(
答案 0 :(得分:0)
该错误与Redux DevTools Chrome扩展程序集成有关,该集成使您可以在浏览器中直观地查看Redux存储。安装Redux DevTools扩展名可以解决问题。如果您不想使用该扩展程序,则只需省略以下代码即可删除与该扩展程序的集成:
,
window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()