React 的错误提示

发布时间:2019-08-19 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了React 的错误提示脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

一、使用 JXS 报错

Uncaught SyntaxError: Unexpected token <

原因:凡是在页面中直接使用 JSX 的地方,都要加上 type="text/babel",在引用 JS 文件的地方加上 type="text/babel"

二、表达式引号

     Minified React error #94;
     
    // 错误
    <h1 onClick="{this.handleClickOnTitle}">React</h1>
    // 正确
    <h1 onClick={this.handleClickOnTitle}>React</h1>

{}表达式不需要引号括起来

三、static defaultProps

static defaultPRops = {
    likedText: '取消',
    unlikedText: '点赞'
}
//由于是用ES6 class语法创建组件,其内部只允许定义方法,而不能定义属性,class的属性只能定义在class之外。所以defaultProps要写在**组件外部**

LikeButton.defaultProps = {
        likedText: '取消',
        unlikedText: '点赞'
    }

四、代码书写不对

 Uncaught TypeError: Super exPression must either be null or a function, not undefined

这个错误一般是 某个地方书写不对

例如:

React.component     //  首字母应该大写

五、输入值属性


Failed prop type: You provided a `value` prop to a form field without an `onChange` handler. This will render a read-only field. If the field should be mutable use `defaultValue`. Otherwise, set either `onChange` or `readOnly`

原因:在输入上设置了一个值属性,但是不提供任何处理程序来更新它
1、设置默认值--defaultValue
2、设置只读--readOnly
3、设置更改函数--onChange

六、table属性