Skip to content

QueryFactory

For usage after instantiation, see Query.

Creates a ChimericQuery wrapping an RTK Query endpoint.

import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
import { ChimericQueryFactory } from '@chimeric/rtk-query';
// 1. Define your RTK Query API
const api = createApi({
reducerPath: 'api',
baseQuery: fetchBaseQuery({ baseUrl: '/api' }),
endpoints: (builder) => ({
getUser: builder.query<User, { id: string }>({
query: (params) => `users/${params.id}`,
}),
getAllTodos: builder.query<Todo[], void>({
query: () => 'todos',
}),
}),
});
// 2. Wrap endpoints with chimeric factories
const getUser = ChimericQueryFactory({
store,
endpoint: api.endpoints.getUser,
endpointName: 'getUser',
api,
});
const getAllTodos = ChimericQueryFactory({
store,
endpoint: api.endpoints.getAllTodos,
endpointName: 'getAllTodos',
api,
});
PropertyTypeDescription
storeRedux storeStore with dispatch and getState
endpointApiEndpointQueryRTK Query endpoint (e.g., api.endpoints.getUser)
endpointNamestringName of the endpoint
apiRTK Query APIThe createApi result (needed for usePrefetch)

Reactive path:

Native OptionTypeDescription
skipbooleanRTK Query skip option
refetchOnMountOrArgChangeboolean | numberRTK refetch behavior

Idiomatic path:

Native OptionTypeDescription
(inherits from)StartQueryActionCreatorOptionsRTK Query initiate options

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


Config without store. Returns only .useHook() and .usePrefetchHook().