I am doing a huge project and I am having some issues with it.
Every time I click the login button, it takes a while to make the database connection, and if this button is an alert and you click it multiple times, it will show the alert multiple times as well.
This is the button:
<TouchableOpacity
style={styles.submitButton}
onPress={
() => this.login(this.state.email, this.state.password)
}>
<Text style={styles.submitButtonText}>Login</Text>
</TouchableOpacity>
I would like to disable the button after clicking it so the alert error only appears once.
This is where I want to put the code to deactivate the button:
if (respo == 'Wrong name or password.') {
alert("Wrong Username and Password.");
} else {
if (respo.user.uid > 0) {
if (Object.values(respo.user.roles).indexOf("student user") > -1) {
AsyncStorage.setItem("u_uid", respo.user.uid);
alert("Login Successfull.");
Actions.home();
} else {
alert("Only Student user is allowed to login.");
}
}
}
Thank you!
Button
component, which comes with adisabled
prop?styles
as aprop
, and thecolor prop
renders
different views for bothandroid
andios
.Kindly check the docs here