Embedded analytics SDK API
    Preparing search index...

    Function useAction

    • Triggers a pre-existing Metabase action. The first arg is the action's numeric id or its entity_id string; supply TParameters as the first generic to type the execute argument, and optionally TKind as the second generic to type the discriminated result shape.

      Without TKind, result defaults to a union of every possible response body (AnyActionResult) — authors who don't know the kind upfront can narrow with "<key>" in result instead of casting from Record<string, unknown>.

      useAction<{ name: string; email: string }, "create">(42);

      Unlike the query hooks, this does NOT run on mount — the caller invokes execute explicitly from an event handler. To gate execution conditionally, branch in the event handler (e.g. if (!user.canEdit) return;) before calling execute.

      Type Parameters

      • TParameters extends Record<string, unknown> = Record<string, unknown>
      • TKind extends ActionKind | undefined = undefined

      Parameters

      Returns UseActionResult<TParameters, TKind>

      • error: ActionExecuteError | null

        Last thrown error, normalized to the public ActionExecuteError shape, or null.

      • execute: (parameters: TParameters) => Promise<ActionResultForKind<TKind> | null>

        Trigger the action with the given parameters. Returns the response body on success AND throws on failure — the same error is stored in error for render-time consumers. Resolves to the discriminated result shape (see ActionResultForKind<TKind>); when TKind is omitted it resolves to AnyActionResult, narrowable via "<key>" in r.

        Resolves to null (without making a request) when actionId is null or the SDK is not yet initialized — guard the host-side caller with if (!actionId) return; if these cases are reachable.

      • isExecuting: boolean
      • reset: () => void

        Clear result and error.

      • result: ActionResultForKind<TKind> | null

        Last response, or null before first call and after reset().