This file contains 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
export function todosLoader(queryClient: QueryClient) { | |
return async function (): Promise<{ todos: Task[] }> { | |
const { queryKey, queryFn } = todosQuery(); | |
// It does the trick for returning any data we have in the cache, even if it's stale. | |
// If the query does not exist, queryClient.fetchQuery will be called and its results returned. | |
const todos = (await queryClient.ensureQueryData({ | |
queryKey, | |
queryFn, | |
})) as Task[]; |
OlderNewer