I have a Firebase database that contains Ethereum addresses for a whitelist. I'm a beginner, I just started with fireBase. I've done a lot of research and I got stuck. I would retrieve all the addresses inside the database and store them in an array using usestate in React JS.
Thank you very much
CodePudding user response:
import { collection, getDocs } from "firebase/firestore";
import { useState } from "react";
const [state,setState] = useState([])
const querySnapshot = await getDocs(collection(db, "nameOfYourCollection"));
querySnapshot.forEach((doc) => {
setState(prevState=>[...prevState,doc.data()])
});
CodePudding user response:
If you have errors that say collection, getDocs, db not defined... try to import this with '@'.
I mean:
import { collection, getDocs } from "@firebase/firestore"
import { db } from "@lib/firebase"