2.0.0
Changes
BREAKING CHANGES
All built-in APIs(such as useDefaultOptions
, functional enabled
and setData
) are no longer support. Please use middleware
instead.
Before:
const useUser = createQuery<Response, Variables>({
// ...
enabled: (data) => !data
})
After 2.0.0
const disabledIfHasData: Middleware<QueryHook<Response, Variables>> = useQueryNext => {
return options => {
const client = useQueryClient()
const hasData = () =>
!!client.getQueryData(useUser.getKey(options.variables))
return useQueryNext({
...options,
enabled: options.enabled ?? !hasData(),
})
}
}
const useUser = createQuery<Response, Variables>({
// ...
use: [disabledIfHasData],
})