how can i retrieve document IDs in a useEffect
using firebase realtime database?
This works great but however i need every single document id aswell.
CodePudding user response:
This is how you can get keys from array in RTDB:
onValue(dbRef, (snapshot) => {
snapshot.forEach((childSnapshot) => {
const childKey = childSnapshot.key;
const childData = childSnapshot.val();
// ...
});
}, {
onlyOnce: true
});
You need to get to childSnapshots using forEach or for loop.