react.js - react-alert - 未捕获的不变违规:无效的钩子调用

我的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,我正在使用的库。


任何人都可以帮助我如何解决这个问题?


catspeake
浏览 172回答 2
2回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript