Skip to content

InfiniteQueryFactory

For usage after instantiation, see InfiniteQuery.

Creates a ChimericInfiniteQuery wrapping an RTK Query endpoint with infinite query support.

import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
import { ChimericInfiniteQueryFactory } from '@chimeric/rtk-query';
// 1. Define your RTK Query API with an infinite query endpoint
const api = createApi({
reducerPath: 'api',
baseQuery: fetchBaseQuery({ baseUrl: '/api' }),
endpoints: (builder) => ({
getArchivedTodos: builder.infiniteQuery<ArchivedTodoPage, void, number>({
infiniteQueryOptions: {
initialPageParam: 0,
getNextPageParam: (lastPage) => lastPage.next_cursor ?? undefined,
},
queryFn: async ({ pageParam }) => {
const data = await fetch(
`/api/archived-todo?page=${pageParam}&limit=10`,
).then((r) => r.json());
return { data };
},
}),
}),
});
// 2. Wrap the endpoint with a chimeric factory
const getArchivedTodos = ChimericInfiniteQueryFactory({
store,
endpoint: api.endpoints.getArchivedTodos,
endpointName: 'getArchivedTodos',
api,
});
PropertyTypeDescription
storeRedux storeStore with dispatch and getState
endpointApiEndpointQueryRTK Query endpoint with infinite query options
endpointNamestringName of the endpoint
apiRTK Query APIThe createApi result

Reactive path:

Native OptionTypeDescription
skipbooleanRTK Query skip option
refetchOnMountOrArgChangeboolean | numberRTK refetch behavior

Idiomatic path:

Native OptionTypeDescription
direction'forward' | 'backward'Pagination direction
(inherits from)StartQueryActionCreatorOptionsRTK Query initiate options

Same config. Returns only the idiomatic callable + .prefetch().


Config without store. Returns only .useHook().