使用 React Hooks 时出现 UseState 错误

2023-11-29

我正在使用钩子,但出现此错误

第25行:React Hook“React.useState”在函数“contact”中被调用,该函数既不是React函数组件,也不是自定义React Hook函数react-hooks/rules-of-hooks 第26行:React Hook“React.useState”在函数“contact”中被调用,该函数既不是React函数组件,也不是自定义React Hook函数react-hooks/rules-of-hooks 第27行:React Hook“React.useState”在函数“contact”中被调用,该函数既不是React函数组件,也不是自定义React Hook函数react-hooks/rules-of-hooks

export default function contact() {

 const [messageInput, setMessageInput] = React.useState("");
 const [email, setEmail] = React.useState("");
 const [name, setName] = React.useState("");

 const enables =
   messageInput.length > 0 &&
   email.length > 0 &&
   name.length > 0;


 return (

<div className="App">

我之前做过一个类似的项目,我用我的旧项目作为参考。这在我的旧项目中没有发生。


rules-of-hooks lint 规则使用命名约定来推断函数的用途。函数开头为use假设是钩子。以大写字母开头的函数被假定为组件。contact两者都不是。将其更改为Contact.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 React Hooks 时出现 UseState 错误 的相关文章

随机推荐