Comments (2)
You should assign generics to infer options
correctly.
If you don't assign generics, the type of options
in usePrefetchQuery
will be:
UseQueryOptions<unknown, Error, unknown, QueryKey>
but the type of factory.example()
is:
UseQueryOptions<string, Error, string, string[]> & {
initialData?: undefined;
} & {
queryKey: DataTag<string[], string>;
}
You can see the generics are completely different each other.
So you can fix the problem as follows:
function usePrefetchQuery<
TQueryFnData = unknown,
TError = DefaultError,
TData = TQueryFnData,
TQueryKey extends QueryKey = QueryKey,
>(options: UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>) {
const queryClient = useQueryClient()
if (!queryClient.getQueryState(options.queryKey)) {
queryClient.ensureQueryData(options).catch(() => {})
}
}
// I will work!
usePrefetchQuery(factory.example());
from query.
@mitchell-up oh thank you so much!
from query.
Related Issues (20)
- Bug: Error when hydrating an query that threw error HOT 1
- useQuery() hook vulnerable to type errors HOT 1
- [svelte-query] `getQueryData`/`setQueryData` fail to infer query data type from `queryOptions` HOT 3
- ESLint Plugin: Flat Config Support HOT 1
- [react-query][Bug?]When invalidating useSuspenseQuery queries with invalidateQueries, the refetch process does not run. HOT 1
- useIsFetching stops tracking queries immediately HOT 1
- No QueryClient set, use QueryClientProvider to set one
- Cannot read properties of null (reading 'useRef') with Vite Module Federation HOT 1
- docs: make the incompatibility of `skipToken` and `refetch` more detailed HOT 1
- "React Example: Nextjs Suspense Streaming" doesn't work HOT 1
- `useSuspenseQuery` does not retry after `fetchQuery` returned an error HOT 4
- invoking `suspense()` with `enabled: false` will wait infinite while ssr HOT 3
- Vercel build error when using HydrationBoundary HOT 4
- No information about matchQuery in the docs HOT 2
- Hydration Boundary not working with 2 or more children HOT 1
- Query that is not enabled returns the result stored in the cache HOT 4
- preserveSymlinks breaks useQuery return type HOT 1
- React Query v5.48.0 Cannot read properties of undefined (reading 'length') when using infinite queries HOT 1
- Enabled exactOptionalPropertyTypes causes error when trying to use the optional selector
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from query.