React-使用中报错处理ERROR

React常见错误

①Uncaught SyntaxError: Inline Babel script: Adjacent JSX elements must be wrapped in an enclosing tag
虚拟DOM中只能有一个根标签

②Warning: Invalid DOM property class. Did you mean className?
in div 在react的jsx语法中,class是一个类的关键词,所以标签的class属性要改为className

③Uncaught SyntaxError: Inline Babel script: Unterminated JSX contents
在jsx中,所有的标签都要有闭合,比如input br img hr 要写成<input /> <br />

④Warning: Invalid DOM property for. Did you mean htmlFor?
in label

in div 在react的jsx语法中,for是循环的关键词,所以标签的for属性要改为htmlFor

1.Warning: The tag is unrecognized in this browser. If you meant to render a React component, start its name with an uppercase
letter
.

在react中,组件名称要以大写字母开头

2.Warning: 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.

表单元素设置value属性之后,默认就是只读属性,如果想要让它变成可以修改的控件需要设置onChange事件,让这个控件变成受控组件。


版权声明:本文为weixin_45760365原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。