I'm trying to populate a menu list from my PouchDB database, but I can't seem to return anything from within the promise I call after calling get on the db.
Here is my code:
<MenuList>
{this.populateSavedClues()}
</MenuList>
.
.
.
populateSavedClues() {
var db = this.db;
db.get('roomClues').then(function (doc) {
if (doc.clues == null || doc.clues == array()) {
return <MenuItem onClick={() => this.handleClose()} align='start' size='small' >You have no saved clues for this room</MenuItem>;
}
else {
return doc.clues.map((clue) => <MenuItem onClick={() => this.selectClue(clue)} align='start' size='small' >{clue}</MenuItem>);
}
}).catch(function (err) {
if(err.name=="not_found") {
return <MenuItem onClick={() => this.handleClose()} align='start' size='small' >You have no saved clues for this room</MenuItem>;
}
});
}
Now right now I'm specifically testing the catch condition. I know for a fact its hitting the not found in my tests, and hitting that return statement within, but my menu gets no items and is still empty. I've tested outside the promises and just make this function return the menu item with no other logic and that also works, so its something about trying to return within the catch promise and I am at my wits end trying to figure out why that return is not going all the way through to the MenuList call. What do I need to do to return the menu item?