Skip to content

Commit

Permalink
docs: using server components in islands (#2416)
Browse files Browse the repository at this point in the history
After reading the discussion at #2369, this PR introduces a small
addition to the docs which highlights how you can use server components
within islands.

This, coupled with the existing docs, should hopefully give people
enough of an example to understand that islands provide the
interactivity layer, and that server components within them can be
hydrated and made interactive too.

Closes #2369
  • Loading branch information
kerimhudson committed Apr 30, 2024
1 parent 9c1e523 commit bc75101
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions docs/latest/concepts/islands.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,34 @@ export default function Home() {
}
```

You can also create shared components in your `components/` directory, which can
be used in both static content and interactive islands. When these components
are used within islands, interactivity can be added, such as `onClick` handlers
(using an `onClick` handler on a button outside of an island will not fire).

```tsx islands/my-island.tsx
import { useSignal } from "@preact/signals";
import { ComponentChildren } from "preact";
import Card from "../components/Card.tsx";
import Button from "../components/Button.tsx";

interface Props {
children: ComponentChildren;
}

export default function MyIsland({ children }: Props) {
const count = useSignal(0);

return (
<Card>
Counter is at {count}.{" "}
<Button onClick={() => (count.value += 1)}>+</Button>
{children}
</Card>
);
}
```

## Passing other props to islands

Passing props to islands is supported, but only if the props are serializable.
Expand Down

0 comments on commit bc75101

Please sign in to comment.