Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: using server components in islands #2416

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 28 additions & 0 deletions docs/latest/concepts/islands.md
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>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I file like we should add a sentence that this click handler will only fire when this component is inside ./islands or referenced inside an island. I'm worried that the component name here suggests that this component would be treated as an island.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @marvinhagemeister

I hoped the positioning in the docs would have helped clarify that as I didn't want to be overly verbose, but I've added a sentence as you mention to make sure it's explicitly known. Let me know what you think.

{children}
</Card>
);
}
```

## Passing other props to islands

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