I’m making a login page, and I want to reduce the number of attempts a user has, but only if the new email they entered matches the previous one they had entered i.e the email has not been edited.
I’ve tried comparing the current email
state to prevState.email
, but they both have the same value anytime a user makes an edit.
Input field:
<Input
type="email"
placeholder="Email"
value={email}
onChange={(e) =>
this.setState({ email: e.target.value, showError: false })
}
></Input>
This is where I check:
componentDidUpdate(prevProps, prevState) {
const { isLoginSuccess, loginError } = this.props;
const { invalidCredentialCount, email} = this.state;
if (
isLoginSuccess !== prevProps.isLoginSuccess
) {
if (isLoginSuccess) {
} else if (loginError) {
//it goes into the if statement even after the user makes a change
if (prevState.invalidCredentialCount > 0 && prevState.email === email) {
this.setState({
invalidCredentialCount: invalidCredentialCount - 1, //reduce count by 1
});
}
}
}
}
I’m quite stuck on how to make this work