Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/content/docs/en/guides/integrations-guide/solid-js.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,47 @@ Non-hydrating [`client:only` components][astro-client-only] are not automaticall

Feel free to add additional Suspense boundaries according to your preference.

### Sharing state across islands

Comment on lines +228 to +229

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We'll need a <Since /> here, I believe this should be the right version:

Suggested change
### Sharing state across islands
### Sharing state across islands
<Since pkg="@astrojs/solid-js" v="7.1.0" />

By default, each Astro [island](/en/concepts/islands/) hydrates independently with its own isolated state. To share reactive state between multiple Solid islands on the same page, use `createIslandSignal` from `@astrojs/solid-js/signals`:

```astro
---
// src/pages/index.astro
import { createIslandSignal } from '@astrojs/solid-js/signals';
import Counter from '../components/Counter';
import Display from '../components/Display';

const [count, setCount] = createIslandSignal(0);
---
<Counter count={count} setCount={setCount} client:load />
<Display count={count} client:load />
```

Both components receive the same signal. When `Counter` updates the value, `Display` will reactively re-render with the new value.

Solid components consume the signal using the standard accessor/setter pattern:

```tsx
// src/components/Counter.tsx
export default function Counter(props) {
return (
<div>
<button onClick={() => props.setCount((v) => v - 1)}>-</button>
<span>{props.count()}</span>
<button onClick={() => props.setCount((v) => v + 1)}>+</button>
</div>
);
}
```

Signals can also be passed inside arrays and objects:

```astro
<MyComponent items={["text", count, 42]} client:load />
<MyComponent config={{ label: "Count", value: count }} client:load />
```

[astro-integration]: /en/guides/integrations/

[astro-ui-frameworks]: /en/guides/framework-components/#using-framework-components
Expand Down
Loading