React之错误记录

222 阅读1分钟

React在使用过程中的错误记录,会一直记录的...

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. 循环生成组件的key值

Warning: Each child in a list should have a unique "key" prop

问题描述:列表中的每个子项都应具有唯一的“键”属性。基本都是因为在循环生成多个组件的时候,没有给组件加上key引起的,所以报错警告。
解决方法:此时我们需要循环生成多个组件中,加上key值(唯一值)那么就不会报错了。

3. 函数的取名问题

React Hook “useState” is called in function “index” which is neither a React function component or a custom React Hook function.eslint(react-hooks/rules-of-hooks)

问题描述:这里原因是因为函数的取名问题
解决方法:function index(){}, 把函数名改成大写开头 Index() 就消除了报错信息