小编Aks*_*eth的帖子

React Hook "useState" 在函数 "test" 中调用,它既不是 React 函数组件,也不是自定义 React Hook 函数

我正在尝试在我的功能组件中使用 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.
Run Code Online (Sandbox Code Playgroud)

这是相同的代码:

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 …
Run Code Online (Sandbox Code Playgroud)

reactjs react-hooks

3
推荐指数
2
解决办法
6339
查看次数

标签 统计

react-hooks ×1

reactjs ×1