当前位置: 首页 > 知识库问答 >
问题:

React Hook“usestate”在函数“test”中被称为,该函数既不是React函数组件,也不是自定义React Hook函数

贺跃
2023-03-14
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;

提前谢了。

共有1个答案

阴礼骞
2023-03-14

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

函数Person(){}

要了解更多信息,react aslo识别函数名以'use'开头作为自定义挂钩,如

 类似资料: