How to call useMoralisQuery propertly?

This is my current setup, I’m only triggering the useMoralisQuery whenever the user is authenticated, but it’s giving me an error that the user “get” is null…

  const getFavorites = useMoralisQuery(
    "Favorites",
    (query) => query.contains("favorites", user.get("ethAddress")),
    [],
    { autoFetch: false }
  );

 const fetchFavorites = () => {
    if (isAuthenticated)
      getFavorites.fetch({
        onSuccess: (favorites) => {
          // The object was retrieved successfully.
          console.log(favorites)
          setFav(favorites)
        },
        onError: (error) => {
          // The object was not retrieved successfully.
          // error is a Moralis.Error with an error code and message.
        },
      });
    else
      toast.error("You must connect your wallet.")
  };

  useEffect(() => {
    if (isAuthenticated)
      fetchFavorites();
    console.log(isAuthenticated)
  }, [isAuthenticated])

Check your user object in a useEffect to see what it contains.

useEffect(() => {
  console.log("user", user);
}, [user]);

Does your query work if you put in a hardcoded address in your contains?

First it gives me null, then gives me parse user object. For the hardcoded, yes it works with contains.

This is normal. Does user.get("ethAddress") get you a valid address? Check that also in the useEffect.

If it does, possibly the isAuthenticated and user states are updated slightly out of sync. So you could add user to that useEffect:

 useEffect(() => {
    if (isAuthenticated && user)
      fetchFavorites();
    console.log(isAuthenticated)
  }, [isAuthenticated, user])