Caching mechanism error in VueJS #7256
-
Hi everyone, import { supabase } from '@modules/supabase';
import { useQuery } from '@tanstack/vue-query';
import { MaybeRef, computed, toValue } from 'vue';
export function useServicesTitleList(
currentServiceType: MaybeRef<string | undefined>
) {
return useQuery({
queryKey: ['servicesTitleList', currentServiceType],
initialData: [],
staleTime: Infinity,
enabled: computed(() => !!toValue(currentServiceType)),
queryFn: async () => {
const val = toValue(currentServiceType);
if (!val) return [];
const { data } = await supabase
.from('bubble_os_os___wording_prestation')
.select('*')
.eq('type0', val);
return (
data?.map((d) => ({
label: d.display,
value: d.display,
})) ?? []
);
},
});
} Can anyone explains me why when i put If i remove staleTime, everything works, but this fetch everytime the Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You could try with |
Beta Was this translation helpful? Give feedback.
initialData
is treated like a valid response, therefore when you change thequeryKey
it will useinitialData
and do not refetch it due tostaleTime: Infinity
.You could try with
placeholderData
.