🔥 All-Access Pass — $199 USD (Regular $499) · Unlock all 2,836 Astro themes ➔
komal.nakrani
Get All-Access Pass ($199)
ThemesCategoriesDocsBlogTips & TricksPricingGet All-Access Pass ($199)
Components & Islands••By Komal Nakrani

Astro Island Props: What You Can Pass and How

How Astro island props work: pass serializable data to client:* components, which types survive, why functions fail, and how slots become props in React.

#Astro#Islands#Props#React

You pass props to an Astro island exactly like any component, <Counter client:visible start={5} />, but because the island hydrates in the browser, Astro serializes those props into the HTML. Astro island props must therefore be serializable: strings, numbers, booleans, plain objects and arrays work, as do Date, Map, Set, URL, RegExp, BigInt and typed arrays. Functions and class instances don’t survive the trip.

Key Takeaways

  • Props of a hydrated component are serialized into the page and parsed again on the client.
  • Pass data, not behaviour: no functions, event handlers or class instances.
  • Pass only what the island needs; every prop adds bytes to the HTML.
  • Children and named slots arrive as rendered HTML, which framework components receive as props.

The basics

---
// src/pages/product.astro
import AddToCart from '../components/AddToCart.tsx';
const product = { id: 'sku-42', name: 'Desk lamp', price: 89, tags: ['lighting'] };
---
<AddToCart client:visible product={product} currency="USD" />
// src/components/AddToCart.tsx
type Props = {
  product: { id: string; name: string; price: number; tags: string[] };
  currency: string;
};

export default function AddToCart({ product, currency }: Props) {
  const price = new Intl.NumberFormat('en-US', { style: 'currency', currency }).format(product.price);
  return <button type="button">Add {product.name} ({price})</button>;
}

At build time, Astro renders the button to HTML and writes the props into an astro-island element as data. In the browser, the framework hydrates using those same props, so server and client markup match.

What survives serialization

Type Works as an island prop
string, number, boolean, null, undefined Yes
Plain objects and arrays Yes
Date, Map, Set, URL, RegExp, BigInt Yes
Typed arrays such as Uint8Array Yes
Functions and event handlers No
Class instances, DOM nodes, Promises No

If you need behaviour, put it inside the island. Instead of passing onAdd={...}, pass the data the island needs (an ID, an endpoint URL) and let the component do the work. For communication between islands, use a shared Nano Store or custom events.

Props on components without a client:* directive are never serialized, because nothing runs in the browser. Passing a function to a server-only React component is fine.

Keep island props small

Everything you pass ends up in the HTML. Passing a whole content collection entry, with its rendered body, to an island that only needs a title and an ID is a common way to bloat a page:

---
// Avoid: sends the whole entry to the browser
// <Likes client:visible post={post} />

// Better: send only what the island uses
---
<Likes client:visible postId={post.id} initialCount={post.data.likes} />

View the page source and search for astro-island if a page feels heavy. The props attribute shows exactly what each island received.

Children and named slots

Children passed to a framework island are rendered by Astro first and handed over as static HTML:

---
import Card from '../components/Card.tsx';
---
<Card client:idle>
  <h2 slot="title">Pricing</h2>
  <p>Plans start at $9 a month.</p>
</Card>

In React, Preact and Solid, the default slot arrives as children and each named slot as a prop with the slot’s name (a kebab-case name such as card-title becomes cardTitle). In Svelte and Vue, use their native slot syntax. Slot content is HTML, not live components, so Astro components inside it render once on the server.

// src/components/Card.tsx
import type { ReactNode } from 'react';
export default function Card({ title, children }: { title?: ReactNode; children?: ReactNode }) {
  return <section className="card">{title}{children}</section>;
}

Typing props

Framework components type their own props. To catch mistakes from the Astro side too, export the type and reuse it where you build the data. Our guide to typing Astro props with TypeScript covers the patterns, and Astro islands architecture explains hydration in depth. For where components live in a project, see the folder structure docs; every one of our Astro themes follows that layout.

FAQ

Why can’t I pass a function to an Astro island?

Island props are serialized into HTML so the browser can hydrate the component. Functions can’t be serialized, so Astro has nothing to send. Define the function inside the island instead.

Do island props update after hydration?

No. Props are read once at hydration. After that, the island manages its own state. To change data later, use state inside the island, a shared store, or fetch from an endpoint.

Can I pass an Astro component as a prop to a React island?

Not as a component. Pass it as slot content instead; Astro renders it to HTML and the island receives it as children or a named prop.