TanStackT
TanStack14mo ago
5 replies
awake-maroon

Is it possible to make reusable useQuery in composables?

Hi, I wanted to create custom hooks in composables like so:
import { useQuery } from "@tanstack/vue-query";
import { useAuthStore } from "../stores/useAuthStore";

export const useMe = () => {
  const { isAuth } = useAuthStore();
  const userClient = useUserClient();

  return useQuery({
    queryFn: () => userClient.getMe,
    queryKey: [queryKeys.value.user.me],
    enabled: isAuth.value,
  });
};


but I get error

[nuxt] [request error] [unhandled] [500] Cannot stringify a function

Is there any possibility to make easy reusable hooks/functions to use in components without triggering this error?
Was this page helpful?