I've got a modal (some sort of custom toast) which shows up on the following class called Details
when the showModal variable is set to true.
class Details extends React.Component {
constructor(props) {
super(props);
this.state = {
error: null,
code: null,
publication: null,
loading: false,
circleloading: false,
showModal: false
};
this.setReady = this.setReady.bind(this);
}
handleSendMessage(event, errors) {
event.preventDefault();
let currentComponent = this;
let ownerEmail = this.state.publication.userEmail;
let title = this.state.publication.title;
let emailDTO = JsonService.getJSONParsed(event.target);
emailDTO.ownerEmail = ownerEmail;
emailDTO.title = title;
if (Object.keys(errors).length === 0) {
this.setState({
loading: true,
showModal: false,
});
UserService.sendMessage(emailDTO).then(function(response) {
currentComponent.setState({
loading: false,
showModal: true, // This works fine, but it turns out the modal then gets shown after every render
});
});
}
}
render() {
return (
<div>
<ToastNotification
show={this.state.showModal}
title={t('details.messageTitle')}
information={t('details.messageDetail')}
type='Information'
checkModal={false}
specialCloseModal={false}
/>
<ImageVisualizer
publicationid={query.publicationid}
maxImages={this.state.publication.images}
isFavourite={this.state.publication.favourite}
page='Details'
imageClass='imageSize'
containerClass='img-with-tag mySlides'
nextClass='next-image-details pointer centerArrow'
previousClass='prev-image-details pointer centerArrow'
setReady={this.setReady}
index={0}
/>
</div>
);
}
}
export default withRouter(withTranslation()(Details));
The thing is showModal is set to true after UserService.sendMessage gets called, which is ok. The modal shows up.
But the problem is whenever a render is triggered by another function or something else the modal is shown again? How can I set showModal to false after showing up?