TanStackT
TanStack4y ago
2 replies
verbal-lime

Difference between `fetchQuery` and `ensureQueryData`?

The docs for queryClient.ensureQueryData says:

ensureQueryData is an asynchronous function that can be used to get an existing query's cached data. If the query does not exist, queryClient.fetchQuery will be called and its results returned.

But, isn't that what fetchQuery already does kind of? Returns the query data if it's already fetched, and does the fetch if it's not?
Was this page helpful?