I'm reusing the query in the right way? #333
-
|
Hello! I'm using pinia-colada in Nuxt 3. I have the following query in src/colada/queries/profile.ts import { defineQuery, useQuery } from "@pinia/colada";
export const useProfile = defineQuery(() => {
const { $csrfFetch } = useNuxtApp();
return useQuery({
key: ["profile"],
query: async () => {
const res = await $csrfFetch("/api/profiles", {
method: "GET",
});
return res;
},
});
});I'm calling that query in a component called user-menu.vue: const {
error,
data,
isLoading,
refetch,
} = useProfile();and in a profiles.vue page: const {
error,
data,
isLoading,
refetch,
} = useProfile();It's working great since it's synchronized and everything. But I'm not sure if I should use the cached data on the page instead of running the query, because every time I leave the page and go back to it, it refetches the data. The component is running first since is in the layout. Any thoughts? Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
|
You can control that behavior with |
Beta Was this translation helpful? Give feedback.
Those are in
useQuery(), autocompletion is your friend 😄https://pinia-colada.esm.dev/api/@pinia/colada/interfaces/DefineQueryOptionsTagged.html#refetchOnMount-