diff --git a/packages/connect-query/src/use-infinite-query.test.ts b/packages/connect-query/src/use-infinite-query.test.ts index 59c5f00a..6a39b297 100644 --- a/packages/connect-query/src/use-infinite-query.test.ts +++ b/packages/connect-query/src/use-infinite-query.test.ts @@ -346,4 +346,32 @@ describe("useSuspenseInfiniteQuery", () => { ], }); }); + + it("can be disabled without explicit disableQuery", () => { + const { result } = renderHook( + () => { + return useInfiniteQuery( + methodDescriptor, + { + page: 0n, + }, + { + getNextPageParam: (lastPage) => lastPage.page + 1n, + pageParamKey: "page", + enabled: false, + }, + ); + }, + wrapper( + { + defaultOptions, + }, + mockedPaginatedTransport, + ), + ); + + expect(result.current.data).toBeUndefined(); + expect(result.current.isPending).toBeTruthy(); + expect(result.current.isFetching).toBeFalsy(); + }); }); diff --git a/packages/connect-query/src/use-infinite-query.ts b/packages/connect-query/src/use-infinite-query.ts index 7b0140fe..b1272b66 100644 --- a/packages/connect-query/src/use-infinite-query.ts +++ b/packages/connect-query/src/use-infinite-query.ts @@ -64,7 +64,10 @@ export function useInfiniteQuery< pageParamKey, callOptions, }); - return tsUseInfiniteQuery({ ...options, ...baseOptions }); + // The query cannot be enabled if the base options are disabled, regardless of + // incoming query options. + const enabled = baseOptions.enabled && (options.enabled ?? true); + return tsUseInfiniteQuery({ ...options, ...baseOptions, enabled }); } /**