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

420
Vistas
How to set data in Firebase .onSnapshot()

I'm trying to set data with this function and its not setting the variable. How can I set information for outside use with this?

Here is my code

const docRef = store.collection('users').doc(item.email)
var image;
docRef.onSnapshot((doc) => {
    if (doc.exists) {
        image = doc.data().picture
    }
})

How can I set the image variable within this function to use outside the onSnapshot? This is a React JS project.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

In react you should handle data in state

import React ,{useState} from 'react';

const [image,setImage] = useState('');
 const docRef = store.collection('users').doc(item.email);
 docRef.onSnapshot((doc) => {
     if (doc.exists) {
        setImage(doc.data().picture) // Set Image Here
     } })

now you can work with image const outside the onSnapshot scoop

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