React Hook“ useHistory”在函数“ header”中被调用,该函数既不是React函数的组件,也不是自定义的React Hook函数
import { Link, useHistory } from 'react-router-dom'
function header() {
let history = useHistory()
return (
<header>
<div className="header_buttons">
<Link onClick={history.push('/auth/login')} to='/auth/login'>
<a href="" className='primary-link'>Login</a>
</Link>
</div>
</header>
)}
export default header
Failed to compile.
./src/Header/header.js
Line 6:19: React Hook "useHistory" is called in function "header" which is neither a React function component or a custom React Hook function react-hooks/rules-of-hooks
答案 0 :(得分:1)
反应成分必须大写。将其重命名为Header
。
function Header() {
let history = useHistory();
return (...);
}