Skip to content

2.0.0

Compare
Choose a tag to compare
@liaoliao666 liaoliao666 released this 14 Sep 07:41
· 79 commits to main since this release

Changes

  1. feat: optimize middleware type
  2. feat: remove all built-in APIs

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],
})