Skip to content

Commit 3ee6904

Browse files
authoredMar 3, 2024··
feat(swr): add swrInfiniteOptions property to output.override.swr (#1245)
1 parent 82907c2 commit 3ee6904

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed
 

‎docs/src/pages/reference/configuration/output.md

+24
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,30 @@ module.exports = {
865865
};
866866
```
867867

868+
##### swrInfiniteOptions
869+
870+
Type: `Object`.
871+
872+
Use to override the `useSWRInfinite` options. Check available options [here](https://swr.vercel.app/docs/pagination#parameters)
873+
874+
Example:
875+
876+
```js
877+
module.exports = {
878+
petstore: {
879+
output: {
880+
override: {
881+
swr: {
882+
swrInfiniteOptions: {
883+
initialSize: 10,
884+
},
885+
},
886+
},
887+
},
888+
},
889+
};
890+
```
891+
868892
#### mock
869893

870894
Type: `Object`.

‎packages/core/src/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ export type SwrOptions = {
364364
useInfinite?: boolean;
365365
swrOptions?: any;
366366
swrMutationOptions?: any;
367+
swrInfiniteOptions?: any;
367368
};
368369

369370
export type InputTransformerFn = (spec: OpenAPIObject) => OpenAPIObject;

‎packages/swr/src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,9 @@ ${doc}export const ${camel(
363363
});
364364
365365
const ${queryResultVarName} = useSWRInfinite<Awaited<ReturnType<typeof swrFn>>, TError>(swrKeyLoader, swrFn, ${
366-
swrOptions.options
366+
swrOptions.swrInfiniteOptions
367367
? `{
368-
${stringify(swrOptions.options)?.slice(1, -1)}
368+
${stringify(swrOptions.swrInfiniteOptions)?.slice(1, -1)}
369369
...swrOptions
370370
}`
371371
: 'swrOptions'

‎tests/configs/swr.config.ts

+3
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ export default defineConfig({
121121
swrMutationOptions: {
122122
revalidate: true,
123123
},
124+
swrInfiniteOptions: {
125+
initialSize: 10,
126+
},
124127
},
125128
},
126129
},

0 commit comments

Comments
 (0)
Please sign in to comment.