Sharing state between framework islands helps different parts of a webpage work together smoothly. It lets components built with different tools talk to each other.
You have a button in one island that changes data shown in another island.
You want to keep user info consistent across different parts of the page.
You need to update multiple components when a user interacts with one.
You want to avoid reloading the whole page to share data.
You want to build a fast, interactive site using multiple frameworks.
Syntax
Astro
import { createSignal } from'solid-js';
// Create a shared state signal
const [state, setState] = createSignal(initialValue);
// Pass state and setState as props to islands
<IslandA state={state} setState={setState} />
<IslandB state={state} setState={setState} />
Use a shared state signal or store that multiple islands can access.
Pass the state and update functions as props to each island.
Examples
One island changes the count, another shows it.
Astro
// Create shared state
const [count, setCount] = createSignal(0);
// Island A increments count
<IslandA count={count} setCount={setCount} />
// Island B shows count
<IslandB count={count} />
Load the island on the client to use shared state interactively.
5. You want two islands to share a counter state that increments when either button is clicked. Which approach correctly shares and updates the state across both islands?
hard
A. Declare the signal inside one island and import it directly in the other island
B. Declare a shared signal in the parent Astro component and pass it as a prop to both islands with client:load
C. Use local state inside each island without passing props
D. Declare separate signals inside each island and sync them with events
Solution
Step 1: Understand shared state location
Shared signals must live in a common parent to be passed down.
Step 2: Pass the shared signal as props to both islands
Passing the same signal prop lets both islands update and reflect changes.
Step 3: Use client:load to hydrate both islands for interactivity
client:load enables event handling and reactive updates in islands.
Final Answer:
Declare a shared signal in the parent Astro component and pass it as a prop to both islands with client:load -> Option B
Quick Check:
Shared signal in parent + props + client:load = synced islands [OK]
Hint: Keep shared state in parent and pass to islands with client:load [OK]
Common Mistakes:
Declaring separate signals causing unsynced state
Not passing signal as prop to both islands
Importing signal directly between islands (not supported)
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.