【发布时间】:2020-03-18 06:02:22
【问题描述】:
我正在尝试在我的功能组件中使用 React useState 挂钩,但出现此错误:
Failed to compile
./src/Person/Person.js
Line 5:43: React Hook "useState" is called in function "person" which is neither a React function component or a custom React Hook function react-hooks/rules-of-hooks
Search for the keywords to learn more about each error.
This error occurred during the build time and cannot be dismissed.
这是相同的代码:
import React, {useState} from 'react';
import { tsPropertySignature, directive } from '@babel/types';
const person =props =>{
const [initState,stateChangeFunction]=useState({name:'akie@123'})
return <p>I am from the {}</p>
}
export default person;
提前致谢。
【问题讨论】:
-
如果你使用
useState你的函数名应该以大写字母开头,如果没有useState那么大写/小写字母都可以
标签: reactjs react-hooks