MutationFactory
For usage after instantiation, see Mutation.
ChimericMutationFactory
Section titled “ChimericMutationFactory”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 APIconst 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 factoriesconst updateUser = ChimericMutationFactory({ store, endpoint: api.endpoints.updateUser,});
const deleteUser = ChimericMutationFactory({ store, endpoint: api.endpoints.deleteUser,});Config
Section titled “Config”| Property | Type | Description |
|---|---|---|
store | Redux store | Store with dispatch |
endpoint | ApiEndpointMutation | RTK Query mutation endpoint |
RTK-Specific Native Options
Section titled “RTK-Specific Native Options”Idiomatic path:
| Native Option | Type | Description |
|---|---|---|
track | boolean | Whether to track the mutation in the store |
fixedCacheKey | string | Fixed cache key for the mutation |
Reactive path:
| Native Option | Type | Description |
|---|---|---|
fixedCacheKey | string | Shared cache key across components |
IdiomaticMutationFactory
Section titled “IdiomaticMutationFactory”Same config. Returns only the idiomatic callable.
ReactiveMutationFactory
Section titled “ReactiveMutationFactory”Config without store. Returns only the reactive .useHook().