UNPKG

@kubb/plugin-react-query

Version:

Generator react-query hooks

70 lines (63 loc) 2.48 kB
/** * Generated by Kubb (https://kubb.dev/). * Do not edit manually. */ import client from 'axios' import type { UseMutationOptions, QueryClient } from '@tanstack/react-query' import type { RequestConfig, ResponseErrorConfig } from 'axios' import { useMutation } from '@tanstack/react-query' export const updatePetWithFormMutationKey = () => [{ url: '/pet/{pet_id}' }] as const export type UpdatePetWithFormMutationKey = ReturnType<typeof updatePetWithFormMutationKey> /** * @summary Updates a pet in the store with form data * {@link /pet/:pet_id} */ export async function updatePetWithForm( petId: UpdatePetWithFormPathParams['petId'], data?: UpdatePetWithFormMutationRequest, params?: UpdatePetWithFormQueryParams, config: Partial<RequestConfig<UpdatePetWithFormMutationRequest>> & { client?: typeof client } = {}, ) { const { client: request = client, ...requestConfig } = config const res = await request<UpdatePetWithFormMutationResponse, ResponseErrorConfig<UpdatePetWithForm405>, UpdatePetWithFormMutationRequest>({ method: 'POST', url: `/pet/${pet_id}`, params, data: updatePetWithFormMutationRequest.parse(data), ...requestConfig, }) return updatePetWithFormMutationResponse.parse(res.data) } /** * @summary Updates a pet in the store with form data * {@link /pet/:pet_id} */ export function useUpdatePetWithForm<TContext>( options: { mutation?: UseMutationOptions< UpdatePetWithFormMutationResponse, ResponseErrorConfig<UpdatePetWithForm405>, { petId: UpdatePetWithFormPathParams['petId']; data?: UpdatePetWithFormMutationRequest; params?: UpdatePetWithFormQueryParams }, TContext > & { client?: QueryClient } client?: Partial<RequestConfig<UpdatePetWithFormMutationRequest>> & { client?: typeof client } } = {}, ) { const { mutation: { client: queryClient, ...mutationOptions } = {}, client: config = {} } = options ?? {} const mutationKey = mutationOptions?.mutationKey ?? updatePetWithFormMutationKey() return useMutation< UpdatePetWithFormMutationResponse, ResponseErrorConfig<UpdatePetWithForm405>, { petId: UpdatePetWithFormPathParams['petId']; data?: UpdatePetWithFormMutationRequest; params?: UpdatePetWithFormQueryParams }, TContext >( { mutationFn: async ({ petId, data, params }) => { return updatePetWithForm(petId, data, params, config) }, mutationKey, ...mutationOptions, }, queryClient, ) }