1

Don't know what's the issue here.

If anyone know what's the issue here then please help me out.

I am trying to make anyonymous login.

Don't know what's the issue here.

If anyone know what's the issue here then please help me out.

I am trying to make anyonymous login.

     const LoginManager = () => {
     // Set an initializing state whilst Firebase connects
     const [initializing, setInitializing] = useState(true);
     const [user, setUser] = useGlobal('user');
   
     // Handle user state changes
     function onAuthStateChanged(user) {
       setUser(user);
       if (initializing) {
         setInitializing(false);
       }
     }
   
     useEffect(() => {
       const subscriber = auth().onAuthStateChanged(onAuthStateChanged);
       return subscriber; // unsubscribe on unmount
       // eslint-disable-next-line react-hooks/exhaustive-deps
       if (initializing) {
         return null;
       }
       if (!user) {
         return auth()
           .signInAnonymously()
           .then(() => {
             console.log('User signed in anonymously');
           })
           .catch((error) => {
             if (error.code === 'auth/operation-not-allowed') {
               console.log('Enable anonymous in your firebase console.');
             }
             console.log(error);
           });
       } else {
         console.log('User already signed in.');
       }
     }, []);
   
     return null;
   }; 
  • The error says to include the dependencies you're using in the dependency array or remove the array for good. Try to remove that array at the end of useEffect (it will become something like this useEffect( () => {} ) instead of useEffect ( () => {}, [] ) – dianaqqq Apr 27 '21 at 11:02
  • Does this answer your question? [How to fix missing dependency warning when using useEffect React Hook?](https://stackoverflow.com/questions/55840294/how-to-fix-missing-dependency-warning-when-using-useeffect-react-hook) – Kai Apr 27 '21 at 15:02

0 Answers0