为什么一直报“React.createClass is deprecated”

刚学react,跟着网上做个例子,但一直报:

Warning: Accessing PropTypes via the main React package is deprecated. Use the prop-types package from npm instead.

Warning: AnimateChild: React.createClass is deprecated and will be removed in version 16. Use plain JavaScript classes instead. If you're not yet ready to migrate, create-react-class is available on npm as a drop-in replacement.

我自己排查了一下是因为===》“import { Button } from 'antd';”这个导致的问题。
在网上查了半天,没找到适合的答案,我要做的项目需要这个样式库,没有办法不用,

“import {Router,Route,hashHistory} from 'react-router';”做路由的时候也是一样的报这个错误,头疼不已。。。。
灵机一动,感觉好像是我版本的问题,大家帮忙看下,因为刚学不久,还是有很多不懂的地方,大家多指指点点。。。

组件里什么都没有,就是简单的例子

下面是配置文件

"dependencies": {
    "antd": "^2.1.0",
    "babel-plugin-react-html-attrs": "^2.0.0",
    "babel-preset-es2015": "^6.14.0",
    "babel-preset-react": "^6.11.1",
    "babelify": "^7.3.0",
    "css-loader": "^0.25.0",
    "json-loader": "^0.5.4",
    "react": "^15.5.4",
    "react-dom": "^15.3.2",
    "react-mixin": "^2.0.2",
    "react-router": "^2.8.1",
    "style-loader": "^0.13.1",
    "webpack": "^1.15.0",
    "webpack-dev-server": "^1.16.1"
  },
  "devDependencies": {
    "babel-core": "^6.24.1",
    "babel-loader": "^7.0.0",
    "babel-preset-react": "^6.24.1",
    "react": "^15.5.4",
    "react-dom": "^15.5.4"
  }
var debug = process.env.NODE_ENV !== "production";
var webpack = require('webpack');
var path = require('path');

module.exports = {
  context: path.join(__dirname),
  devtool: debug ? "inline-sourcemap" : null,
  entry: "./src/js/root.js",
  module: {
    loaders: [
      {
        test: /\.js?$/,
        exclude: /(node_modules)/,
        loader: 'babel-loader',
        query: {
          presets: ['react', 'es2015'],
          plugins: ['react-html-attrs'],
        }
      },
      //下面是使用ant-design的配置文件
      {
        test: /\.css$/,
        loader: 'style-loader!css-loader'
      },
    ]
  },
  output: {
    path: __dirname,
    filename: "./src/bundle.js"
  },
  plugins: debug ? [] : [
    new webpack.optimize.DedupePlugin(),
    new webpack.optimize.OccurenceOrderPlugin(),
    new webpack.optimize.UglifyJsPlugin({ mangle: false, sourcemap: false }),
  ],
};
阅读 9.7k
3 个回答

你这个只是warning,并不影响开发的,其实你不用管的。

至于出现warning的原因,里面已经说的很清楚了:

  • PropTypes已经不建议直接从react中获取了,而是从prop-types组件中获取

  • createClass也会在react 16中去除,所以不建议使用。

可能是因为你引入的某些组件还在使用这些东西吧,不过只是warning并不影响开发的。

把React.createClass改为React.Component就OK.

跟我出现的问题一样,用排除法排除了一下,发现还是antd-mobile的问题,但是也不知道怎么解决,因为antd-mobile里面也引用了prop-types,所以不知道怎么解决,不过确实不影响开发,看着难受!

推荐问题