0
0
Astroframework~20 mins

Sharing state between framework islands in Astro - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Astro State Sharing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
How does state sharing affect component updates?

In Astro, when two framework islands share state via a global store, what happens when the state changes?

AAll islands subscribed to the shared state re-render automatically.
BOnly the island that triggered the state change re-renders.
CNo islands re-render until the page is refreshed manually.
DOnly islands with local state re-render, ignoring the shared state.
Attempts:
2 left
💡 Hint

Think about how reactive state management works across components.

📝 Syntax
intermediate
2:00remaining
Identify the correct way to pass shared state between Astro islands

Which code snippet correctly passes a shared state object from Astro to two different framework islands?

A<IslandA client:load state={sharedState} /><IslandB client:load sharedState={sharedState} />
B<IslandA client:load sharedState={sharedState} /><IslandB client:load sharedState={sharedState} />
C<IslandA client:load state={sharedState} /><IslandB client:load state={sharedState} />
D<IslandA client:load state={sharedState} /><IslandB client:load state={sharedState} sharedState={sharedState} />
Attempts:
2 left
💡 Hint

Look for consistent prop names passed to both islands.

🔧 Debug
advanced
2:00remaining
Why does the second island not update when shared state changes?

Given two Astro islands sharing a state object, the first island updates correctly, but the second does not reflect changes. What is the most likely cause?

AAstro does not support state sharing between islands.
BThe shared state object is immutable and cannot trigger updates.
CThe first island overwrites the shared state with a local copy.
DThe second island is not subscribed to the shared state changes properly.
Attempts:
2 left
💡 Hint

Consider how subscriptions to reactive state work.

🧠 Conceptual
advanced
2:00remaining
What is the best practice for sharing state between framework islands in Astro?

Which approach best ensures consistent and reactive state sharing between multiple framework islands in Astro?

AUse a global reactive store or context accessible by all islands.
BPass state only once during initial render and avoid updates.
CDuplicate state in each island to prevent cross-dependencies.
DUse URL query parameters to share state between islands.
Attempts:
2 left
💡 Hint

Think about how to keep multiple components in sync reactively.

state_output
expert
3:00remaining
What is the output after updating shared state in two Astro islands?

Consider two Astro islands sharing a reactive state object with a counter starting at 0. Island A increments the counter by 1, and Island B increments it by 2. What is the final counter value after both updates?

Astro
const sharedState = reactive({ counter: 0 });

// Island A code
sharedState.counter += 1;

// Island B code
sharedState.counter += 2;

console.log(sharedState.counter);
A0
B3
C2
D1
Attempts:
2 left
💡 Hint

Remember that both increments affect the same shared state object.