Reputation: 498
I have this simple Firebase Realtime Database:
and I have the inner Id
(in blue), How Can I Fetch the key
(in red) using ReactJS?
I've already read the Firebase Realtime Database Docs (Modular SDK v9) but I did not see a way to do so. I'll appreciate any help.
Upvotes: 0
Views: 151
Reputation: 7418
Some basic code if you want to get the whole list for ID 1 would look like this:
import { getDatabase, get, ref } from "firebase/database";
const getData = async () => {
const db = getDatabase();
const snap = await get(ref(db, `Lists/${id1}`));
snap.forEach((r) => {
console.log("key", r.key);
console.log("value", r.val()); // red
console.log("id", r.val()["id"]); // blue
});
};
Upvotes: 1