无法在Redux开发工具中查看状态数据

时间:2019-11-07 20:09:24

标签: reactjs redux redux-devtools

enter image description here我正在学习redux,并想出了一个使用网络服务的示例 返回数据。一切正常。但是我配置了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

enter image description here

1 个答案:

答案 0 :(得分: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;

App.js

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

const App = () => {
  return (
    <Provider store={store}>
      <BrowserRouter basename={process.env.PUBLIC_URL}>
        // ...
      </BrowserRouter>
    </Provider>
  );
};