Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

146
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda