1

在此处输入图像描述我正在学习 redux 并想出了一个使用返回数据的 web 服务的示例。一切正常。但是我在下面配置了 redux 开发者工具。

我收到一条错误消息,说我的商店被分配了一个值但从未使用过,当我进入我的开发工具时,我看不到我的状态数据。难道我做错了什么?

        import React from 'react';
        import ReactDOM from 'react-dom';
        import { BrowserRouter as Router, Route } from 'react-router-dom';
        import promise from 'redux-promise';
        import { Provider } from 'react-redux';
        import { createStore, applyMiddleware, compose } from 'redux';

        import reducers from './reducers';
        import ProductsIndex from './components/products_index';

        const createStoreWithMiddleware = applyMiddleware(promise)(createStore);

        const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
        const store = createStore(
          reducers,
          composeEnhancers(applyMiddleware())
        );

        ReactDOM.render(
          <Provider store={createStoreWithMiddleware(reducers)}>
           <Router>
            <div>
              <Route path="/" component={ProductsIndex} />
            </div>
           </Router>
          </Provider>
          , document.querySelector('#root'));

错误:第 14:7 行:“商店”被分配了一个值,但从未使用过 no-unused-vars

在此处输入图像描述

4

1 回答 1

0

这是我通常做的事情。

configureStore.js

import { createStore, applyMiddleware, compose } from "redux";
import thunk from "redux-thunk";
import logger from "redux-logger";
import createRootReducer from "../reducers";

const middleware = window.ENV.environment === "local" ? [thunk, logger] : [thunk];
const composEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
const enhancer = composEnhancers(applyMiddleware(...middleware));

const configureStore = (initialState) => {
  return createStore(createRootReducer(), initialState, enhancer);
};

export default configureStore;

应用程序.js

import configureStore from "./configureStore";
const store = configureStore();

const App = () => {
  return (
    <Provider store={store}>
      <BrowserRouter basename={process.env.PUBLIC_URL}>
        // ...
      </BrowserRouter>
    </Provider>
  );
};
于 2019-11-08T13:11:48.547 回答