React 踩坑记录

1.React-router error: super expression must either be null or a function

原因:引入babel后写ES6风格的代码:

       class ComponentXX extends React.component{} 这里的C小写了,导致产生这个bug

       改为大写就可以 ,不引入router不会产生这个bug

2.React-router 引入Link的时候,在ES6风格的代码下应该这样写:

      import {Link} from "react-router";   哪怕只有一个Link也要用花括号括起来,否则会让react报类型不正确的错误。

3. React中需要使用 async/wait的时候需要做如下几件事

npm install babel-preset-stage-0 --save-dev
npm install --save-dev babel-plugin-transform-runtime
npm install --save babel-runtime

    然后在.babelrc中进行如下配置:

{
 "presets": [ "es2015", "stage-0","react"],
 "plugins": [
    ["transform-runtime", {
      "polyfill": false,
      "regenerator": true
    }]
  ]
}

如果还用到了eslint插件,还需要将.eslintrc中的规则更改一下

{
    "no-constant-condition":[
       "warn",{
        "checkLoops":false
       }
     ],
    "no-fallthrough":["warn",{
       "commentPattern": "break[\\s\\w]*omitted"
    }]
}

 

 

     

 

转载于:https://www.cnblogs.com/JhoneLee/p/5724297.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值