错误
第6:44行:在函数“ app”中调用React Hook“ useState”,该函数既不是React函数组件也不是自定义的React Hook函数react-hooks / rules-of-hooks
搜索关键字以详细了解每个错误。
答案 0 :(得分:0)
我遇到了一个带有打字稿的脚本,将组件名称更改为以大写字母开头为我解决。
答案 1 :(得分:0)
您正在使用useState挂钩,而不是在函数中导入React和useState挂钩
import React,{useState} from "react";
//use a capital letter in the begging of your component name
export const YourComponent = () =>{
//Now you can use the useState hook here in a react functional component
const [personsState, setPersonsState ] = useState({ persons: [
{name: 'Mann', age:'20'},
{name: 'Mab', age: '25'},
{name: 'Bar', age: '43'}
] })
return(
<div>
//you can use personsState here now
</div>
)
}
答案 2 :(得分:0)
create-react-app版本3 +
更新的React版本需要组件
包含要大写的React Hooks(PascalCase)。
含义:组件名称及其导出(名称)。
将两个(名称)应用程序更改为App。