Write functions that run on the server, and can be called by the browser.
npx create-astro --template basics --yes astro-actions-project
pnpm create astro --template basics --yes astro-actions-project
yarn create astro --template basics --yes astro-actions-project
npm install lilnasy/astro-actions
pnpm add lilnasy/astro-actions
yarn add lilnasy/astro-actions
// astro.config.mjs
import actions from 'astro-actions'
export default defineConfig({
integrations: [actions()]
})
// src/actions.ts
export async function hello() {
return 'Hello, world!'
}
---
// src/pages/index.astro
---
<script>
import { hello } from "astro:actions/client"
const message = await hello()
console.log(message)
</script>
Yes! You can use the astro:actions/client
module in any framework component, including React, Vue, Svelte, Solid, and more.
Primitives (strings, numbers, booleans), plain objects, Set
, Map
, Error
, ArrayBuffer
, and TypedArray
. Please create a discussion if you would like to see more.
Everywhere astro can be deployed. Keep in mind that this feature is only relevant to the server output, you need an SSR deployment to use this.