我的react.js應用程序中有這段代碼: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班級中,每當用戶嘗試創建帳戶時,它只需要在兩個字段中輸入的密碼是否相同。據此,它應該創建一個警報。但它正在崩潰并給我這個錯誤:Uncaught Invariant Violation: Invalid hook call. Hooks can only be called inside of the body of a function component.react-alert,我正在使用的庫。任何人都可以幫助我如何解決這個問題?
react.js - react-alert - 未捕獲的不變違規:無效的鉤子調用
catspeake
2021-10-21 13:25:01