/** * Mutation Hook Factory * Factory function for creating typed React Query hooks for POST/PUT/DELETE requests */ import type { ApiMutationOptions, ServiceOptions, UseMutationResult } from '@plyaz/types/api'; import type { EndpointsList } from '../../endpoints'; import type { FetchResponse } from 'fetchff'; import type { ClientEventManager } from '@/api/client'; /** * Factory for creating typed mutation hooks (POST, PUT, PATCH, DELETE) * Wraps service functions with React Query's useMutation hook * * The hook accepts service options and React Query options with full override capabilities. * * @template TData - The type of data returned by the mutation * @template TError - The type of error (defaults to Error) * @template TVariables - The type of variables passed to the mutation * @template TContext - The type of context for optimistic updates (defaults to unknown) * @template TEndpoints - The type of endpoints configuration * * @param serviceFn - The service function to wrap (e.g., createCampaign) * @param defaultOptions - Default mutation options to apply to every call * @returns A hook function that can be used in React components * * @example * ```typescript * // Create a mutation hook from a service function * export function useCreateCampaign( * serviceOptions?: ServiceOptions, * mutationOptions?: UseMutationOptions * ) { * return createApiMutation( * createCampaign, * {} // default options * )(serviceOptions, mutationOptions); * } * * // Use in a component - with full override control * function CreateCampaignForm() { * const queryClient = useQueryClient(); * const { mutate, isPending } = useCreateCampaign( * { apiConfig: { timeout: 10000 } }, // service options override * { * onSuccess: (campaign) => { * queryClient.invalidateQueries({ queryKey: ['campaigns'] }); * toast.success(`Campaign ${campaign.name} created!`); * }, * } * ); * * const handleSubmit = (data) => mutate(data); * return
; * } * ``` */ export declare function createApiMutation