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 <home> 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事件,让这个控件变成受控组件。

 

 

 

posted @   JackieDYH  阅读(22)  评论(0编辑  收藏  举报  
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示