I use here a modal. In the case that everything is good and I added the data to the database, I want to automatically close the modal with the line "this.props.closeModal" but I get the error undefined is not an object (evaluating this.props)
closeModal is called from EmailChildConnect.js field and changeshowTaskVisible value
Any ideas?
ConnectModal.js
class ConnectModal extends React.Component {
addAdultConnexion = async () => {
if (this.state.emailAdult !== "") {
//add to the firebase in the case that is good
this.props.closeModal;
else {
Alert.alert("", "the email does not exist");
};
}
else {
Alert.alert("", "field is required");
}
};
render() {
return (
<CustomBackground>
<TouchableOpacity
onPress={this.props.closeModal}
>
<AntDesign name="close" size={WIDTH / 17.2} color={colors.black} />
</TouchableOpacity>
<View>
<TextInput
onChangeText={(text) => this.setState({ emailAdult: text })}
value={this.state.emailAdult}/>
<CustomValidationButton onPress={() => this.addAdultConnexion()}>
<Text>add</Text>
</CustomValidationButton>
</View>
</CustomBackground>
);
}
}
EmailChildConnect.js :
class EmailChildConnect extends React.Component {
state = {
showTaskVisible: false,
};
toggleisModal() {
this.setState({ showTaskVisible: !this.state.showTaskVisible });
}
render() {
const email = this.props.email;
return (
<View>
<Modal
animationType="slide"
visible={this.state.showTaskVisible}
onRequestClose={() => this.toggleisModal()}
>
<ConnectModal email={email} closeModal={() => this.toggleisModal()} />
</Modal>
<RenderListEmail
onPress={() => this.toggleisModal()}
children1={email.name}
children2={email.childEmail}
/>
</View>
);
}
}