Skip to content

Commit

Permalink
feat(swr): add swrInfiniteOptions property to output.override.swr (
Browse files Browse the repository at this point in the history
  • Loading branch information
soartec-lab authored Mar 3, 2024
1 parent 82907c2 commit 3ee6904
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
24 changes: 24 additions & 0 deletions docs/src/pages/reference/configuration/output.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ export type SwrOptions = {
useInfinite?: boolean;
swrOptions?: any;
swrMutationOptions?: any;
swrInfiniteOptions?: any;
};

export type InputTransformerFn = (spec: OpenAPIObject) => OpenAPIObject;
Expand Down
4 changes: 2 additions & 2 deletions packages/swr/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,9 @@ ${doc}export const ${camel(
});
const ${queryResultVarName} = useSWRInfinite<Awaited<ReturnType<typeof swrFn>>, TError>(swrKeyLoader, swrFn, ${
swrOptions.options
swrOptions.swrInfiniteOptions
? `{
${stringify(swrOptions.options)?.slice(1, -1)}
${stringify(swrOptions.swrInfiniteOptions)?.slice(1, -1)}
...swrOptions
}`
: 'swrOptions'
Expand Down
3 changes: 3 additions & 0 deletions tests/configs/swr.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ export default defineConfig({
swrMutationOptions: {
revalidate: true,
},
swrInfiniteOptions: {
initialSize: 10,
},
},
},
},
Expand Down

0 comments on commit 3ee6904

Please sign in to comment.