TanStackT
TanStack3y ago
1 reply
wet-aqua

Undefined data returned from useQuery hook

Hello friends!
I am trying to get some users from my back end but I get undefined instead.
Here is the code :

//fetch users
  const { isLoading, error, usersData } = useQuery({
    queryKey: ["usersData"],
    queryFn: () => fetch("/api/user").then(res => res.json())
  });

  if (isLoading) return "Loading...";

  if (error) return "An error has occurred: " + error.message;

  console.log("usersData: ", usersData);


Any ideas?
Was this page helpful?