Closed meaningg closed 1 year ago
I don't have any experience with React, but I reckon the db code is now triggered to run each redraw cycle
Yes, it did create a new connection for each rendering. I managed to fix it by throwing the initialization of the database and the initial list to useEffect
useEffect(() => {
return () => {
const db = new AceBaseClient({
host: "localhost",
port: 5757,
dbname: "mydb",
https: false,
});
setDb(db);
getPostsList(db);
};
}, []);
function getPostsList(db) {
db.ref("postsTest")
.get()
.then((snap) => {
const posts = [];
const data = snap.val();
for (let i in data) {
posts.push(data[i]);
}
setPosts(posts);
setPostsIsLoading(false);
});
}
When receiving data from a remote server made on acebase-server to the frontend made on acebase-client new sockets start constantly connecting and it comes up to two hundred in a couple of seconds upd: This happens when the page is refreshed and blocks other actions with the database, such as adding new items
Code:
(Probably my mistake here somewhere, but I can't figure out where :))