Skip to content

Commit

Permalink
errors checked
Browse files Browse the repository at this point in the history
  • Loading branch information
avibedi1768 committed Sep 13, 2023
1 parent 2ae20c1 commit e0fc9ba
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/Components/jsx/Profile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,19 @@ function Profile() {

//for msgs: 0 to n
function loop(n) {
const addMsgs = []
for (var i = 0; i < n; i++) {
console.log(i)
get(ref(db, 'username/' + user + '/messages/' + i + '/message'))
let promises = [];
for (let i = 0; i < n; i++) {
let promise = get(ref(db, 'username/' + user + '/messages/' + i + '/message'))
.then((snapshot) => {
let message = snapshot.val()
console.log(message)
addMsgs.push(message)
})
return snapshot.val();
});
promises.push(promise);
}
console.log(addMsgs)
setMsgs(addMsgs)

Promise.all(promises).then((messages) => {
console.log(messages);
setMsgs(messages);
});
}

return (
Expand Down

0 comments on commit e0fc9ba

Please sign in to comment.