I'm trying to make use of actions, and am dealing with trying to understand how schemas and data are processed.
getActionResult()
Type: (action: TAction) => ActionReturnType<TAction> | undefined
Added in: [email protected]
getActionResult() is a function that returns the result of an Action submission. This accepts an action function as an argument (e.g. actions.logout) and returns a data or error object when a submission is received. Otherwise, it will return undefined.
src/pages/index.astro
---
import { actions } from 'astro:actions';
const result = Astro.getActionResult(actions.logout);
---
<form action={actions.logout}>
<button type="submit">Log out</button>
</form>
{result?.error && <p>Failed to log out. Please try again.</p>}
In this other example:
src/pages/products/[slug].astro
---
import { actions } from 'astro:actions';
const result = Astro.getActionResult(actions.addToCart);
---
{result && !result.error && (
<p class="success">Added {result.data.productName} to cart</p>
)}
<!--...-->
I can't understand how / when the data actually transfers, and how/when it's ready. I'm trying to use HTMX to generate API calls to endpoints that use actions to return formatted HTML.