'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]);


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source