Closed ArturKhantsevich closed 1 year ago
Docs example is a typo. There already support register middlewares globally but no typescript. You can simply add @ts-ignore
to solve this problem
new QueryClient({
defaultOptions: {
queries: {
// @ts-ignore
use: [middleware],
},
},
})
You can try this
import { createQuery as createQueryFactory } from 'react-query-kit'
function createQuery<Response, Variables, Error>(
options: Parameters<typeof createQueryFactory<Response, Variables, Error>>[0]
) {
return createQueryFactory<Response, Variables, Error>({
...options,
use: [requestIdAttacher, fetchQueryAttacher, ...options.use],
})
}
const usePosts = createQuery({ queryKey: ..., queryFn: ..., }) // has additional features from pre-defined middleware
If you use default middleware using defaultOptions
and add middleware with createQuery
as far as I understand, createQuery
will replace the ones from defaults, not merge them.
If you use default middleware using
defaultOptions
and add middleware withcreateQuery
as far as I understand,createQuery
will replace the ones from defaults, not merge them.
It will merge them, only for middleware. Just like swr.
Interesting. This is an important stuff and worth putting to the doc.
doc updated.
Hello,
Readme file mentions
createQueryClient
function which should allow to register middlewares globally. The search repo result says that there is no any such functionality defined. Do you have any plans to implement this feature?Thank you for this great package.