亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

React 歷史掛鉤無法正常工作

React 歷史掛鉤無法正常工作

ITMISS 2023-05-25 16:00:02
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
查看完整描述

1 回答

?
慕妹3146593

TA貢獻1820條經驗 獲得超9個贊

React 組件必須大寫。將其重命名為Header.


function Header() {

   let history = useHistory();


   return (...);

}


查看完整回答
反對 回復 2023-05-25
  • 1 回答
  • 0 關注
  • 143 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號