我的react.js應(yīng)用程序中有這段代碼:import { withAlert} from "react-alert"; class Signup extends React.Component {state={email:'',passwordHash:'',rePasswordHash:''};onButtonClick = () =>{ if(this.state.passwordHash!==this.state.rePasswordHash){ this.props.alert.error("Wrong password"); } else{ this.props.alert.show("Creating new account"); }};render(){ return( <ButtonActor name="Sign In" onButtonClick={this.onButtonClick} /> );}}export default withAlert()(Signup);它在我的SignUp班級(jí)中,每當(dāng)用戶嘗試創(chuàng)建帳戶時(shí),它只需要在兩個(gè)字段中輸入的密碼是否相同。據(jù)此,它應(yīng)該創(chuàng)建一個(gè)警報(bào)。但它正在崩潰并給我這個(gè)錯(cuò)誤:Uncaught Invariant Violation: Invalid hook call. Hooks can only be called inside of the body of a function component.react-alert,我正在使用的庫。任何人都可以幫助我如何解決這個(gè)問題?
react.js - react-alert - 未捕獲的不變違規(guī):無效的鉤子調(diào)用
catspeake
2021-10-21 13:25:01