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

147
Views
onSnapshot is not working properly in useEffect hook

im working on a project on react native and im facing a bug , im trying to fetch the job of the current authenticated user which i stored in the firestore firebase ! i did that in the navigation component inside a useEffect hook so i can get the job of the current authenticated user because every job has it's own stack in the navigation ! but it's not giving me the right job i don't know why ! maybe i'm doing something wrong ? in the onSnapShot im searching for the authenticated user id in the client users if it's there then hes a client , either way hes a delivery ! but still it's not working properly ! its giving me the wrong job , i can share my screen if anyone is down to help , thank you


const [job, setJob] = React.useState("delivery");
 const userJobFromSignup = useSelector((state) => state.auth.job);

 useEffect(() => {
   onAuthStateChanged(authentication, (user) => {
     if (user) {
       setUser(user);
       const unsub = onSnapshot(
         doc(db, "users", "jobs", "client", authentication.currentUser.uid),
         (doc) => {
           if (doc.exists()) {
             setJob("client");
             console.log(job);
           } else {
             console.log(job);
           }
         }
       );
       return () => {
         unsub;
       };
     } else {
       setUser(null);
     }
   });
 }, []);
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

useEffect(() => {
  const unsub = onAuthStateChanged(authentication, (user) => {
    setUser(user);
    onSnapshot(
      doc(db, "users", "jobs", "client", authentication.currentUser.uid),
      (doc) => {
        if (doc.exists()) {
          setJob("client");
          console.log(job);
        } else {
          console.log(job);
        }
      }
    );
  });
  return unsub;
}, []);
about 4 years ago · Santiago Trujillo 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!