diff --git a/docs/src/pages/reference/configuration/output.md b/docs/src/pages/reference/configuration/output.md index c6eb5948e..1039fb7c0 100644 --- a/docs/src/pages/reference/configuration/output.md +++ b/docs/src/pages/reference/configuration/output.md @@ -865,6 +865,30 @@ module.exports = { }; ``` +##### swrInfiniteOptions + +Type: `Object`. + +Use to override the `useSWRInfinite` options. Check available options [here](https://swr.vercel.app/docs/pagination#parameters) + +Example: + +```js +module.exports = { + petstore: { + output: { + override: { + swr: { + swrInfiniteOptions: { + initialSize: 10, + }, + }, + }, + }, + }, +}; +``` + #### mock Type: `Object`. diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 62193a1b0..a54bb2186 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -364,6 +364,7 @@ export type SwrOptions = { useInfinite?: boolean; swrOptions?: any; swrMutationOptions?: any; + swrInfiniteOptions?: any; }; export type InputTransformerFn = (spec: OpenAPIObject) => OpenAPIObject; diff --git a/packages/swr/src/index.ts b/packages/swr/src/index.ts index c9a8e8769..13130ca8b 100644 --- a/packages/swr/src/index.ts +++ b/packages/swr/src/index.ts @@ -363,9 +363,9 @@ ${doc}export const ${camel( }); const ${queryResultVarName} = useSWRInfinite>, TError>(swrKeyLoader, swrFn, ${ - swrOptions.options + swrOptions.swrInfiniteOptions ? `{ - ${stringify(swrOptions.options)?.slice(1, -1)} + ${stringify(swrOptions.swrInfiniteOptions)?.slice(1, -1)} ...swrOptions }` : 'swrOptions' diff --git a/tests/configs/swr.config.ts b/tests/configs/swr.config.ts index 3fba4b34a..abe188fde 100644 --- a/tests/configs/swr.config.ts +++ b/tests/configs/swr.config.ts @@ -121,6 +121,9 @@ export default defineConfig({ swrMutationOptions: { revalidate: true, }, + swrInfiniteOptions: { + initialSize: 10, + }, }, }, },