Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

getting data from firebase

// Necessary Imports
import { useEffect, useState } from "react";
import { db } from "relative path of your firebase config file";
import { collection, onSnapshot } from "firebase/firestore";

// Code inside component
const [data, setData] = useState([]);
useEffect(
        () =>
            onSnapshot(collection(db, "collectionName"), (snapshot) => {
                setData(
                    snapshot.docs.map((doc) => {
                        return { ...doc.data(), id: doc.id };
                    })
                );
            }),
		[]);


console.log(data);
Comment

get data firebase

        const collectionRef = collection(db, "DATA-COLLECTION");
        const docSnap = (async () => await getDocs(collectionRef))();

        useEffect(() => {
                docSnap.then((data) => {
                        data.forEach((doc) => {
                                console.log('doc: ', doc);
                                console.log(doc.data());
                        });
                });
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript ean13 checksum generate 
Javascript :: .then message.delete 
Javascript :: practice javascript 
Javascript :: How to have hotjar in react-hotjar 
Javascript :: vue 3 props 
Javascript :: vue not loading env variables 
Javascript :: formdata is empty after append in angular 
Javascript :: javascript function declaration vs arrow function 
Javascript :: leaflet js mobile popup not opening 
Javascript :: react hooks in codepen 
Javascript :: validate ajax nonce request wordpress 
Javascript :: javascript Use clearTimeout() Method 
Javascript :: detect javascript disabled 
Javascript :: javascript create object from key value pairs 
Javascript :: window.focus and window.blur jquery 
Javascript :: phantomjs in angular 
Javascript :: create slug in express 
Javascript :: objeto con método javascript 
Javascript :: js addeventlistener input searcb mobile 
Javascript :: palindrome string js 
Javascript :: close button react 
Javascript :: get parent class javascript 
Javascript :: jquery limit words in string 
Javascript :: buscar una frase e un string js 
Javascript :: clear inteval 
Javascript :: create own rules jquery 
Javascript :: javascript change first letter to uppercase 
Javascript :: Find All Less Than Equal To In MongoDB 
Javascript :: brain.js 
Javascript :: nested array in json 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =