node.js - Update react state after removing Mongoose record -
need little how update state after removing mongo database record mongoose.
you should able see whats happening code below, working fine, issue 'remove action'. removing record database need refresh see changes.
i rerun 'get characters' function in then of remove action, update state expected not sure how this.
on page load:
componentdidmount() { adminstore.listen(this.onchange); adminactions.getcharactercount(); adminactions.getcharacters('http://localhost:3000/api/characters'); }
action - ajax request query url, send response store
getcharacters(query) { requestpromise(query) .then((res) => { var opdata = json.parse(res); this.actions.getcharacterssuccess(opdata.characters); }).catch((err) => { console.log('error:', err); this.actions.getcharactersfail(err) }) }
store - save response action ajax query in state 'characters'
getcharacterssuccess(res) { this.characters = res; }
onclick remove
handleremove(charname) { adminactions.removecharacter(charname); }
remove action
removecharacter(charname) { var options = { method: 'delete', uri: 'http://localhost:3000/api/characters/delete/' + charname, json: true, }; requestpromise(options) .then(() => { // should update state console.log("done"); }).catch((err) => { console.log('error:', err); }) }
Comments
Post a Comment