Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

322
Vistas
I have a question about Cloud Firestore V9 and using React Js. In one of my docs, there is a map. How do I access this map?

firebase screenshot

enter image description here

There's a function named getSomethingTEST that I'm using to get the data. Then I have a 'temporary' button onPress={getSomethingTest}, but probably its going to be a useEffect not a button. Later I was going to set my state var "dataFB" to the tempStore array. But my issue is... I don't know how... So I tried to console.log my results of tempStore. And I got this.. the results in console Which I believe is a nested object inside of an array. So I tried some basic things like tempStore[0].name but its of course undefined. Also I wasn't sure how to reference a key of an object that has a space in it. For this example it was "Asem Jawa".

    const firebaseApp = initializeApp({
    apiKey: "Hidden",
    authDomain: "Hidden",
    projectId: "Hidden",
  });

  const db = getFirestore();
  const col_p = collection(db, "WNA-Pasteur");
  const docRef = doc(db, "WNA-Pasteur", "branchData");


  const [dataFB, set_dataFB] = useState([]);

  async function getSomethingTEST() {
    const tempStore = [];
    const docSnap = await getDoc(docRef);
    tempStore.push(docSnap.data());
    console.log(tempStore);
  }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You are fetching a single document and docSnap.data() is an object containing that document's data. You don't have to push it an array that way.

async function getSomethingTEST() {
  const docSnap = await getDoc(docRef);
  console.log(docSnap.data().name)  
}

This should log the name but in your case, you don't have a property name in your object so it'll be undefined.

I wasn't sure how to reference a key of an object that has a space in it.

You can use brackets notation:

console.log(docSnap.data()["Asem Jawa"] || "Field missing")
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda