我正在尝试学习Redux,所以我创建了一个测试应用,但似乎我无法应用中间件并创建我的商店,因为我收到错误'createStoreWithMiddleware' is not defined
。
我的index.js:
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter as Router } from 'react-router-dom';
import { Provider } from 'react-redux';
import Header from './components/header';
import Footer from './components/footer';
import Content from './components/content';
import { createStore, applyMiddleware } from 'redux';
import ReduxPromise from 'redux-promise';
import reducers from './reducers';
import './index.css';
import './App.css';
class App extends Component {
render() {
return (
<Router>
<div className="App">
<Header />
<Content />
<Footer />
</div>
</Router>
);
}}
const createStoreWithMiddleWare = applyMiddleware(ReduxPromise)(createStore);
ReactDOM.render(
<Provider store={createStoreWithMiddleware(reducers)}>
<App />
</Provider>,
document.getElementById('root'));
我已经尝试过在课堂上设置提供程序,但这似乎也无法正常工作。可能是一个简单的问题,感谢任何帮助。
答案 0 :(得分:2)
您需要创建商店,然后添加中间件:
const createStoreWithMiddleWare = createStore(reducers, applyMiddleware(ReduxPromise));
您的提供商应该如下所示:
<Provider store={createStoreWithMiddleware}>