我正在嘗試根據(jù)prop( isSignUp) 是true還是false在我的狀態(tài)下向 SIGN UP 或 LOGIN 用戶發(fā)送 POST 請求。我想要發(fā)生的事情:如果是真的,我希望一個 API 端點被擊中,如果isSignUp不是,另一個被擊中。各個端點都可以工作,但是當我將所有東西連接起來時,我只能讓人們登錄,而一旦他們注冊就無法登錄。狀態(tài):state = { controls: { email: { elementType: "input", elementConfig: { type: "email", placeholder: "Email Address" }, value: "", validation: { required: true, // must not be empty isEmail: true }, valid: false, touched: false }, isSignUp: true }};處理程序:handleSubmit = event => { this.props.onAuth( this.state.controls.email.value, this.state.controls.password.value, this.state.controls.isSignUp ); event.preventDefault(); }; switchAuthModeHandler = () => { this.setState(prevState => { console.log(prevState); return { isSignUp: !prevState.isSignUp }; }); };切換按鈕文本和觸發(fā) authModeHandler 的邏輯 return ( <div className={classes.Auth}> <form onSubmit={this.handleSubmit}> {form} <Button btnType="Success">SUBMIT</Button> </form> <Button clicked={this.switchAuthModeHandler} btnType="Danger"> SWITCH TO {this.state.isSignUp ? "SIGN IN" : "SIGN UP"} {console.log(this.state.isSignUp)} </Button> </div> );const mapDispatchToProps = dispatch => { return { onAuth: (email, password, isSignUp) => dispatch(actions.auth(email, password, isSignUp)) };};觸發(fā) POST 請求以登錄或注冊用戶的操作export const auth = (email, password, isSignUp) => { return dispatch => { dispatch(authStart()); const authData = { email: email, password: password, returnSecureToken: true };
如何有條件地發(fā)送 POST 請求以登錄或注冊用戶
GCT1015
2022-07-01 17:03:43