![](/img/trans.png)
[英]React Hook "useState" is called in function "increaseCounter" that is neither a React function component nor a custom React Hook function
[英]React Hook "useState" is called in function "nav" that is neither a React function component nor a custom React Hook function
import {useState} from 'react'
const nav = () => {
const [activeNav, setActiveNav] = useState('#')
}
我試圖建立一個導航欄。 我收到這個錯誤我不知道為什么
React Hook "useState" is called in function "nav" that is neither a React function component nor a custom React Hook function. React component names must start with an uppercase letter. React Hook names must start with the word "use" react-hooks/rules-of-hooks
基本上,似乎以下一項或兩項是您問題的原因:
nav
不是有效的 React 組件。 React 組件是大寫的。nav
可能不會呈現為 React 組件。 重命名為Nav
,這樣它至少可以正確命名。
import {useState} from 'react'
const Nav = () => {
const [activeNav, setActiveNav] = useState('#');
...
return (
// return valid JSX
);
}
將Nav
渲染為 React 組件:
有效的
<Nav />
無效的
{Nav()}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.