I have a problem with useEffect. When I try to get the auth state of the user after the `onAuthStateChanged`, the number of calls in the useEffect is insanely high. Sometimes it gives this error too:

> 
> Warning: Can't perform a React state update on an unmounted component. This is a no-op, but indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function
> 
> 
> 

[This is the amount of logs after the user login/registers and logout](https://i.stack.imgur.com/M9jpz.png). Maybe i'm not understanding well how useEffect works. Here is the code which uses useEffect:

```js
useEffect(async () => {
    let isCancelled = false;
    await firebase.auth().onAuthStateChanged(async (user) => {
      if (user && !isCancelled) {
          await firebase
          .firestore()
          .collection('users')
          .doc(user.uid)
          .get()
          .then((document) => {
            const userData = document.data()
            console.log(document.data())
            setUser(userData);
            setIsSignedIn(true);
            setLoading(false);
          })
          .catch((error) => {
            setLoading(false);
            alert(error)
          });
        }else{
          console.log('user does not exist')
          setIsSignedIn(false);
          setLoading(false);
        }
    });
    return () => {
      isCancelled = true;
    }
  }, []);

```

[This is the image of it. Maybe it's more clear](https://i.stack.imgur.com/eCkBr.png)