Reactjs “反应钩”;“使用状态”;在函数“中调用”;测试“;它既不是React函数组件,也不是自定义React钩子函数

Reactjs “反应钩”;“使用状态”;在函数“中调用”;测试“;它既不是React函数组件,也不是自定义React钩子函数,reactjs,react-hooks,Reactjs,React Hooks,我试图在我的功能组件中使用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

我试图在我的功能组件中使用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;
import React,{useState}来自“React”;
从'@babel/types'导入{tsPropertySignature,directive};
const person=props=>{
const[initState,stateChangeFunction]=useState({name:'akie@123'})
return我来自{}

} 出口违约人;

提前感谢。

您的组件名称应该大写,它应该如下所示:-

constperson=()=>{
// .......
}
出口违约人;

react在您的情况下,将大写的函数名识别为react函数组件

functionperson(){}

更多信息,请react aslo识别以“use”开头的函数名作为自定义挂钩,如

函数usePeople(){}


如果你使用
useState
你的函数名应该以大写字母开头,如果没有
useState
那么大写字母和小写字母都可以回答你的问题吗?这是恼人的调试!我以为我疯了。谢谢你的帮助。