Skip to content

MutationFactory

For usage after instantiation, see Mutation.

Creates a ChimericMutation wrapping an RTK Query mutation endpoint.

import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
import { ChimericMutationFactory } from '@chimeric/rtk-query';
// 1. Define your RTK Query API
const api = createApi({
reducerPath: 'api',
baseQuery: fetchBaseQuery({ baseUrl: '/api' }),
tagTypes: ['User'],
endpoints: (builder) => ({
updateUser: builder.mutation<User, { id: string; name: string }>({
query: (params) => ({
url: `users/${params.id}`,
method: 'PUT',
body: { name: params.name },
}),
invalidatesTags: ['User'],
}),
deleteUser: builder.mutation<void, { id: string }>({
query: (params) => ({
url: `users/${params.id}`,
method: 'DELETE',
}),
invalidatesTags: ['User'],
}),
}),
});
// 2. Wrap endpoints with chimeric factories
const updateUser = ChimericMutationFactory({
store,
endpoint: api.endpoints.updateUser,
});
const deleteUser = ChimericMutationFactory({
store,
endpoint: api.endpoints.deleteUser,
});
PropertyTypeDescription
storeRedux storeStore with dispatch
endpointApiEndpointMutationRTK Query mutation endpoint

Idiomatic path:

Native OptionTypeDescription
trackbooleanWhether to track the mutation in the store
fixedCacheKeystringFixed cache key for the mutation

Reactive path:

Native OptionTypeDescription
fixedCacheKeystringShared cache key across components

Same config. Returns only the idiomatic callable.


Config without store. Returns only the reactive .useHook().