reactjs - How to asynchronously reset values redux -


--for starters apologies ambiguous title. issue having i'm confused how put title. open edits. basically, using react-redux , have modal in updating contents in database. on update, want reducer state default , close modal. (that straight forward triggering function on update sets values default) however, on update want close modal , display toastr on update or error message response. i have set components , actions toastr.

the problem toastr doesn't display message because before can match constant action store, reducers modal set default. best approach overcome this?

modal.jsx

//update     updateconfig() {             this.props.updateconfignode(node, latestconfigdata); //update action             this.closemodal();          }     closemodal() {         this.props.status(false); //close modal         this.props.update(''); //set update action status 'updated or error' ''       } 

toastr.jsx

    componentdidupdate() {      this.routerconfignotification(this.props.config); //getting store    }     confignotify(config) {         const message = checkforrouterconfigupdatestate(config);     if(message) {             this._addnotificationnormal(message.title, message.type, message.text);           }     } 

utils

    export function checkforrouterconfigupdatestate(routerconfig) {    let message = {};   let messagetext;    switch (_.get(routerconfig, 'updatestatus')) { case '_error':       messagetext = 'an error has been occurred while updating configuration';       return message = {         mode: 'normal',         title: 'error',         type: 'info',         status: _.get(routerconfig, 'updatestatus'),         text: messagetext       };      case '_updated':       messagetext = 'successfully updated';       return message = {         mode: 'normal',         title: 'updated',         type: 'info',         status: _.get(routerconfig, 'updatestatus'),         text: messagetext       }; } } 

i have tried other lifecycle update methods closest have been solving issue use settimeout function know hack , pretty sure there way tackle these sort of async problems. thank in advance.

is this.props.updateconfignode(node, latestconfigdata) promise? if can put closemodal then block it's called when request done.

this.props.updateconfignode(node, latestconfigdata).then(() => {   this.closemodal(); }); 

Comments