T
TanStack3y ago
automatic-azure

Is there a way to store a value on initial load only?

For example, I want to load a booking using useQuery and then only one the first load for that query, I want to set a local variable (notes). So then the booking loads, I can store the notes and then because the save is debounced, I need to keep that notes variables separate.
1 Reply
automatic-azure
automatic-azureOP3y ago
So I can't just do it on every load because the save is debounced, when the refetch happens, it would override anything that isn't currently saved
const notes = ref<string | undefined>();
const { data: booking } = useQuery({
queryKey: ["bookings", "view", { id: options.id }],
queryFn: () => bookingsClient.getBooking(options.id),
onSuccess: (data) => {
if (notes.value === undefined) {
notes.value = data.notes.notes;
}
},
});
const notes = ref<string | undefined>();
const { data: booking } = useQuery({
queryKey: ["bookings", "view", { id: options.id }],
queryFn: () => bookingsClient.getBooking(options.id),
onSuccess: (data) => {
if (notes.value === undefined) {
notes.value = data.notes.notes;
}
},
});
This is my current implementation (vue)

Did you find this page helpful?