Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

424
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!