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

101
Visualizações
UseEffect Ignore Null Dependency

TLDR: I would like to ignore a Null object in the dependency array of useEffect

I don't think this is possible but I have a useEffect that I would like to run that has a dependency of currentUser.uid (basically the user object from Firebase). I was hoping to only have to maintain one menubar for both logged in and logged out states, but when logged out, the currentUser.uid object is null which cause a TypeError for the useEffect. I tried using the Conditional Operator but a) ESLint complains of a missing dependency (currentUser.uid) and b) complex expressions are not allowed in dependencies arrays. Is there any way for me to solve this correctly, ideally without errors? The obvious solution, again, is to use multiple files, one for logged-in, the other for logged out, but ideally I would avoid this.

I've provided some code below to illustrate this if the explanation isn't clear.

useEffect(() => {
    function getCookie(cname) {
      let name = cname + '=';
      let ca = document.cookie.split(';');
      for (let i = 0; i < ca.length; i++) {
        let c = ca[i];
        while (c.charAt(0) === ' ') {
          c = c.substring(1);
        }
        if (c.indexOf(name) === 0) {
          return c.substring(name.length, c.length);
        }
      }
      return '';
    }

    function checkCookie() {
      let color = getCookie('color');

      if (color !== '') {
        console.log('Color already set');
        console.log(color);
        setColor(color);
      } else {
        let account_data = db
          .collection(currentUser.uid)
          .doc('account');
        account_data.get().then((doc) => {
          if (doc.exists) {
            setColor(doc.data().color);
            setCookie('color', doc.data().color, {
              secure: true,
              sameSite: 'none',
            });
          } else {
            console.log('No such document!');
          }
        });
      }
    }
    checkCookie();
  }, [currentUser.uid]);
about 4 years ago · Juan Pablo Isaza
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