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

103
Views
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
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!