#what is the use of Astro.callActions and is it used with SSG or SSR?
4 messages · Page 1 of 1 (latest)
Hi @summer orbit. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
Astro.callAction() lets you run an Action’s server-side handler directly from your Astro component (or endpoint) without going through a client call or an HTML form.
Usage:
---
// In an Astro page or layout
import { actions } from 'astro:actions';
const { data, error } = await Astro.callAction(actions.logout, { userId: '123' });
---
This:
- Takes the Action function (e.g.
actions.logout) as the first argument. - Takes the input object as the second argument.
- Returns the same
{ data, error }shape you’d get when calling the action from the client. [callAction; call from components]
You’d typically use it to:
- Reuse Action logic inside Astro components.
- Call Actions from server endpoints using
context.callAction(). [call from components]
SSG vs SSR
The docs do not explicitly restrict Astro.callAction() to SSG or SSR only. They describe it as part of the Astro render context, and also show it used in normal page scripts. [callAction]
However, Actions in general require a server output (i.e. an adapter and on‑demand rendering) to create callable backend functions. [Actions must be used with server output; On-demand rendering]
So:
- You need an adapter / server output to use Actions at all.
- Once that’s configured (SSR / on‑demand rendering), you can use
Astro.callAction()in your Astro components and server endpoints.