• Hook that returns a function that can be used to perform an api mutation via a method on an API service. Automatically handles loading and error behavior. Use this hook when you want to perform a POST, PUT or DELETE request on an API.

    Type Parameters

    • TResponse

    • TParam1

    • TParam2

    Parameters

    • apiMethod: ((param1, param2) => Promise<TResponse>)

      The method to call on the API service

    • options: ApiMutationOptions<TResponse>

      Options for the hook

      • errorMessage: A function that returns the error message to show when the api call fails
      • showToast: A function that shows a toast message (required)
      • successMessage: A message to show when the api call is successful
      • onSuccess: Callback to run on success

    Returns [((param1, param2?) => Promise<TResponse>), boolean]

    A tuple containing the function to perform the mutation and a boolean indicating if the mutation is in progress

    Note

    Make sure to use .bind() when passing an API method to this hook to ensure that the method can access .this

Generated using TypeDoc