Last active
May 6, 2023 22:26
-
-
Save jarrettgreen/0c8b504dc0f736515162bfb517e3e3d7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ref } from 'vue' | |
import { useQuery, useQueryClient } from '@tanstack/vue-query' | |
import { CheckInService } from "@/services"; | |
export function useCheckInsPendingReviewQuery() { | |
const queryKey = ['checkIns', 'pendingReview']; | |
const checkInsPendingReview = ref([]); | |
const queryClient = useQueryClient(); | |
const cachedCheckins = queryClient.getQueryData(queryKey)?.data; | |
if (cachedCheckins) { | |
console.log('[Cache:Hit]', queryKey) | |
checkInsPendingReview.value = cachedCheckins; // this feels wrong | |
} | |
useQuery({ | |
queryKey: queryKey, | |
queryFn: CheckInService.fetchAllUnReviewed, // this is an axios promise. | |
// using initalData never worked for me. | |
// inititalData: () => queryClient.getQueryData(queryKey)?.data || [], | |
// initialDataUpdatedAt: () => queryClient.getQueryState(queryKey)?.dataUpdatedAt, | |
onSuccess: ({ data }) => { | |
checkInsPendingReview.value = data; // update checkIns when the query succeeds | |
}, | |
}); | |
return { | |
checkInsPendingReview, | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment