Use ensureQueryData
with invalidations
#6424
-
Hello everyone, I had to use To solve this issue I came with this function that have the expected behavior : async function ensureFreshQueryData<
TQueryFnData,
TError,
TData,
TQueryKey extends QueryKey = QueryKey
>(
queryClient: QueryClient,
query: WithRequired<
FetchQueryOptions<TQueryFnData, TError, TData, TQueryKey>,
"queryKey"
>
): Promise<any> {
const state = queryClient.getQueryState(query.queryKey);
const data = queryClient.getQueryData(query.queryKey);
if (!state || state.isInvalidated || !data) {
return await queryClient.fetchQuery(query);
}
return data;
} I am not sure if this is the right way to do that. I would like to know if there is something simpler to do. If not I think that would be a good idea to integrate Thanks a lot ! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
just use |
Beta Was this translation helpful? Give feedback.
just use
fetchQuery
and pass astaleTime
to it.