remove `queryHash` from useQuery options
context
The queryHash is the result of the query key hashing, produced by the queryKeyHashFn. This function defaults to a stable JSON.stringify, but can also be passed in by users to do custom hashing, e.g. when non-json serializable things are used in the queryKey.
According to our TypeScript types, we can also pass in a queryHash directly into useQuery. This is not only undocumented, it's also redundant because you can achieve the same thing with a queryKeyHashFn:
- useQuery({ queryKey, queryFn, queryHash: 'myHash' })
+ useQuery({ queryKey, queryFn, queryKeyHashFn: () => 'myHash' })
proposal
- remove
queryHashfrom useQuery options - we'll still need the
queryHashon the internal typeDefaultedQueryObserverOptions, because that's where it gets set:
https://github.com/TanStack/query/blob/1e0745a6cc80cbdbafc3153812b7982a8f549447/packages/query-core/src/queryClient.ts#L740-L745
Hi @TkDodo , if I understand the issue correctly... this would mean omitting out queryHash option from the UseQueryOptions type used in react query and other similar packages?
I haven't thought it through completely, but removing it from UseQueryOptions and instead adding it to DefaultedQueryObserverOptions was my plan.
looked at this today and I missed a couple of things, mainly hydration. There, we create a query with a specific hash, and we don't have the options to re-execute the hashing functions. I guess we have to close this.