+ 1

Firebase realtime database issues

How do I display specific user details from firebase realtime database using the users uid using javascript

12th May 2022, 5:33 PM
Ikuobase Wisdom Ewaensetin
Ikuobase Wisdom Ewaensetin - avatar
2 Respostas
+ 2
Once you've set up your database on console.firebase.google.com click on the "1 app" button, then the settings icon. Scroll to the bottom of the page and copy your firebase initialization script(make sure npm is selected). The script is usually in this format // Import the functions you need from the SDKs you need import { initializeApp } from "firebase/app"; import { getFirestore } from "firebase/firestore"; // Your web app's Firebase configuration const firebaseConfig = { apiKey: "YOUR-API-KEY", authDomain: "YOUR-AUTH-DOMAIN", projectId: "YOUR-PROJECT-ID", storageBucket: "YOUR-STORAGE-BUCKET", messagingSenderId: "sender id", appId: "your app id" }; // Initialize Firebase const app = initializeApp(firebaseConfig); export default getFirestore(); The script above should be stored in a new firebase.js file. Let's say you have a collection of users named "users" on firebase db. This is how you'll fetch the data import React from 'react' import db from 'firebase' // the newly created file...
20th May 2022, 8:59 AM
Emeh Matthew
Emeh Matthew - avatar
+ 2
contd... import { onSnapshot, collection } from 'firebase/firestore' const [users, setUsers] = React.useState([]); function getUsers() { onSnapshot(collection(db, "users"), snapshot => setUsers(snapshot.docs.map(doc => doc.data()))); } getUsers ();
20th May 2022, 9:04 AM
Emeh Matthew
Emeh Matthew - avatar