Skip to content
Meeko
Type to search the guides and the API reference. Open it from any page with / or Ctrl K; move with the arrow keys and open a result with Enter.
Get started

Contents

On this page

Not translated yet

This page has not been translated into English yet, so it is shown in Spanish.

ApiMutation

interfaz Since 1.2.0

Resultado de useApiMutation(ruta, método): llama a un endpoint de API que no es GET bajo demanda con mutate({ params, query, body }), nunca en SSR, y refleja la última llamada en pending, data y error. Con la opción retrySafe añade RetrySafeMutation.

ts
import type { ApiMutation } from "@meekojs/meeko/framework";

Source code src/app/composables/resources/engine.ts:192

Declaración #

ts
interface ApiMutation<O extends AnyApiOperation> {
	mutate(...input: ApiMutationArguments<O>): Promise<O['output']>
	readonly pending: ReadonlySignal<boolean>
	readonly error: ReadonlySignal<Error | null>
	readonly data: ReadonlySignal<O['output'] | null>
}

Type parameters #

O extends AnyApiOperation

Operación del contrato de API.

Example #

meeko
<script lang="ts">
const remove = useApiMutation("/api/notes/[id]", "DELETE");
async function erase(id: string): Promise<void> {
  await remove.mutate({ params: { id } });
}
</script>
<template><p if:when="remove.error.value">No se pudo borrar.</p></template>

Miembros #

mutate #

método

mutate(...input: ApiMutationArguments<O>): Promise<O['output']>

Llama al endpoint con el token CSRF; devuelve su salida o rechaza con su error. Se puede llamar sin argumentos cuando la operación no exige params, query ni body.

pending #

propiedad sólo lectura

readonly pending: ReadonlySignal<boolean>

true mientras una llamada está en curso.

error #

propiedad sólo lectura

readonly error: ReadonlySignal<Error | null>

Fallo de la última llamada, o null.

data #

propiedad sólo lectura

readonly data: ReadonlySignal<O['output'] | null>

Salida de la última llamada correcta, o null.

See also #

Was this page helpful?

Add a comment

It is sent when you choose “Yes” or “No”. Only the page, your answer and the comment are stored: no cookies and no personal data.

0 of 2000 characters

Edit on GitHub: packages/meeko/src/app/composables/resources/engine.ts