nedb
nedb copied to clipboard
.find event only firing on full electron restart
0
So I switched from working on a mac to working on windows and this weird bug popped up. I have a database(Compendium) and on render of a React component I fire React.useEffect to call a function to pull out some information out of the database. Here is my load function:
export function LoadRaces(callback) {
const returnRaces: Race[] = [];
const Datastore = require("nedb"),
races = new Datastore({ filename: "Compendium.db" });
races.loadDatabase();
console.log("Preloading Races Test");
races.find({ size: { $exists: true } }, function (err, docs) {
console.log("Loading Races");
docs.map((c) => {
returnRaces.push(c);
callback(returnRaces);
});
});
}
my UseEffect is rather simple:
{React.useEffect(() => {
LoadRaces((result) => {
DisplayRaces(result);
});
}, [])}
Here is the problem: When I first start my Electron app via npm run start the LoadRaces function runs how it's supposed to, prints out "Preloading Races Test" followed by "Loading Races" into the console, displays the races how it supposed to. However when I reload the electron app(not close it just go ctrl-R or even force reload) the .find() of the LoadRaces does not run at all it seems.
Update: after a little bit more testing I realized that the database is not being loaded at all after cntr+R Reload or Force Reload