Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(swr): add swrInfiniteOptions property to output.override.swr #1245

Conversation

soartec-lab
Copy link
Collaborator

Status

READY

Description

This PR is a follow up to #1223 and #1225
I added a property swrInfiniteOptions to output.override.swr that extends only the options of useSWRInfinite.

Related PRs

List related PRs against other branches:

Todos

  • Tests
  • Documentation
  • Changelog Entry (unreleased)

Steps to Test or Reproduce

  1. check generated hooks in tests

tests/generated/swr/petstore-override-swr/endpoints.ts:

/**
 * @summary Info for a specific pet
 */
export const useShowPetByIdInfinite = <TError = AxiosError<Error>>(
  petId: string, options?: { swr?:SWRInfiniteConfiguration<Awaited<ReturnType<typeof showPetById>>, TError> & { swrKeyLoader?: SWRInfiniteKeyLoader, enabled?: boolean }, axios?: AxiosRequestConfig }
) => {
  const {swr: swrOptions, axios: axiosOptions} = options ?? {}

  const isEnabled = swrOptions?.enabled !== false && !!(petId)
  const swrKeyLoader = swrOptions?.swrKeyLoader ?? (() => isEnabled ? getShowPetByIdInfiniteKeyLoader(petId) : null);
  const swrFn = () => showPetById(petId, axiosOptions);

  const query = useSWRInfinite<Awaited<ReturnType<typeof swrFn>>, TError>(swrKeyLoader, swrFn, {
     initialSize: 10, 
    ...swrOptions
  })

  return {
    swrKeyLoader,
    ...query
  }
}

@melloware melloware merged commit 3ee6904 into anymaniax:master Mar 3, 2024
2 checks passed
@soartec-lab soartec-lab added the enhancement New feature or request label Mar 6, 2024
@soartec-lab soartec-lab added this to the 6.26.0 milestone Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants