从redux-persist导入PersistGate导致“超级表达式必须为null或函数,且未定义”

时间:2018-07-13 04:22:12

标签: node.js reactjs react-redux redux-persist

我现在正在使用redux-persist在我的react-redux应用程序中进行持久数据存储。我已经根据the documentation进行了设置。永久数据存储似乎还可以,但是当我从PersistGate导入redux-persist/integration/react时,它显示为Uncaught TypeError: Super expression must either be null or a function, not undefined。有人可以帮我吗?

这是我的index.js:

import React from "react";
import ReactDOM from "react-dom";
import { Provider } from "react-redux";
import {createStore} from "redux";
import reducers from "./reducers";
import { persistStore, persistReducer } from 'redux-persist';
import storage from 'redux-persist/lib/storage';
import GG from './containers/gg';
import { PersistGate } from 'redux-persist/integration/react';

const persistConfig = {
  key: 'root',
  storage,
}

const persistedReducer = persistReducer(persistConfig, reducers);
let store = createStore(persistedReducer);
let persistor = persistStore(store);

ReactDOM.render(
  <Provider store={store}>
  <GG/>
  </Provider>,
  document.querySelector(".container")
);

package.json

{
  "name": "redux-simple-starter",
  "version": "1.0.0",
  "description": "Simple starter package for Redux with React and Babel support",
  "main": "index.js",
  "repository": "git@github.com:StephenGrider/ReduxSimpleStarter.git",
  "scripts": {
    "start": "node ./node_modules/webpack-dev-server/bin/webpack-dev-server.js"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "babel-core": "^6.2.1",
    "babel-loader": "^6.2.0",
    "babel-preset-es2015": "^6.1.18",
    "babel-preset-react": "^6.1.18",
    "webpack": "^1.12.9",
    "webpack-dev-server": "^1.14.0"
  },
  "dependencies": {
    "babel-preset-stage-1": "^6.1.18",
    "react": "^0.14.3",
    "react-dom": "^0.14.3",
    "react-redux": "^4.0.0",
    "redux": "^3.0.4",
    "redux-persist": "^5.10.0"
  }
}

感谢您的关注。

1 个答案:

答案 0 :(得分:1)

这是您的React版本的问题。您的React指定版本^0.14.3不包含React.PureComponent的父组件PersistGate uses。这会导致错误,因为超类redux-persist试图扩展React.PureComponent并不存在。这是因为React.PureComponent已添加到React API in version 15.3中。升级您的React版本。