📖 Scenario: You are building a simple website using Astro. Astro lets you use different JavaScript frameworks for small parts of your page, called islands. Each island can use React, Vue, or Svelte components. You want to set up your page with different islands using the right framework for each.
🎯 Goal: Create an Astro page that includes three islands: one React island, one Vue island, and one Svelte island. Each island will show a simple message. You will set up the data, configure which framework to use for each island, and then add the islands to the page.
📋 What You'll Learn
Create a data object with messages for React, Vue, and Svelte islands
Create a configuration variable that maps each island name to its framework
Use Astro's island syntax to render each framework component with the correct message
Complete the Astro page with all three islands included
💡 Why This Matters
🌍 Real World
Astro lets you build fast websites by mixing different JavaScript frameworks only where needed. This project shows how to set up multiple framework islands on one page.
💼 Career
Knowing how to use Astro islands with React, Vue, and Svelte is useful for frontend developers working on modern multi-framework web projects.
Progress0 / 4 steps
1
Set up the messages data object
Create a constant called messages that is an object with these exact entries: react with value 'Hello from React!', vue with value 'Hello from Vue!', and svelte with value 'Hello from Svelte!'.
Astro
Hint
Use const messages = { react: 'Hello from React!', vue: 'Hello from Vue!', svelte: 'Hello from Svelte!' }
2
Create the framework configuration
Create a constant called frameworks that is an object mapping react to 'React', vue to 'Vue', and svelte to 'Svelte'.
Use Astro island syntax to add three islands: <ReactIsland client:load> with message messages.react, <VueIsland client:load> with message messages.vue, and <SvelteIsland client:load> with message messages.svelte. Assume the components are imported as ReactIsland, VueIsland, and SvelteIsland.
Astro
Hint
Use the island components with client:load and pass the correct message prop.
4
Complete the Astro page with imports and islands
Add import statements for ReactIsland from '../components/ReactIsland.jsx', VueIsland from '../components/VueIsland.vue', and SvelteIsland from '../components/SvelteIsland.svelte'. Then include the three islands with their messages as in step 3.
Astro
Hint
Remember to import each island component from its file before using it.
Practice
(1/5)
1. What is the main reason to choose different frameworks for different islands in Astro?
easy
A. To optimize performance by loading only needed code for each island
B. To make the entire page load all frameworks at once
C. To force all islands to use the same framework
D. To avoid using any JavaScript on the page
Solution
Step 1: Understand what islands are in Astro
Islands are small interactive parts of a page that can use different frameworks.
Step 2: Reason why different frameworks are chosen per island
Choosing different frameworks lets you load only the code needed for each island, improving performance.
Final Answer:
To optimize performance by loading only needed code for each island -> Option A
Quick Check:
Performance optimization = B [OK]
Hint: Islands load only needed code to keep pages fast [OK]
Common Mistakes:
Thinking all islands load all frameworks at once
Believing islands must share the same framework
Assuming no JavaScript is used at all
2. Which of the following is the correct way to specify a React island in Astro?
easy
A. <MyComponent client:react />
B. <MyComponent client:only='react' />
C. <MyComponent client:load />
D. <MyComponent client:hydrate />
Solution
Step 1: Recall Astro syntax for framework islands
Astro uses client:only='react' to specify that the component should only load the React framework.
Step 2: Match the correct syntax for React island
The correct syntax to specify a React island is client:only='react'.
Final Answer:
<MyComponent client:only='react' /> -> Option B
Quick Check:
Astro island syntax for React = A [OK]
Hint: Use client:only='react' to specify React islands [OK]
Common Mistakes:
Using client:load without specifying framework
Using client:react which is invalid
Using client:hydrate which is invalid directive
3. Given this Astro island code:
<Counter client:load />
What happens when the page loads?
medium
A. The Counter component loads and runs JavaScript immediately on page load
B. The Counter component never loads JavaScript
C. The Counter component loads JavaScript only when visible on screen
D. The Counter component loads JavaScript only on user interaction
Solution
Step 1: Understand client:load behavior
client:load means the island's JavaScript loads and runs as soon as the page loads.
Step 2: Apply this to the Counter component
The Counter component will load and run its JavaScript immediately when the page loads.
Final Answer:
The Counter component loads and runs JavaScript immediately on page load -> Option A
Quick Check:
client:load = immediate JS load [OK]
Hint: client:load runs JS immediately on page load [OK]
Common Mistakes:
Confusing client:load with client:visible or client:idle
Thinking JS loads only on interaction
Assuming no JS loads at all
4. You wrote this Astro island:
<MyWidget client:only='vue' />
But the widget does not load. What is the likely problem?
medium
A. Astro does not support Vue islands
B. client:only='vue' is invalid syntax
C. You must use client:load instead of client:only
D. You forgot to install the Vue integration in Astro
Solution
Step 1: Check if Vue integration is installed
If the widget does not load, the most likely cause is forgetting to install the Vue integration in Astro.
Step 2: Confirm syntax
client:only='vue' is valid syntax to specify Vue islands.
Final Answer:
You forgot to install the Vue integration in Astro -> Option D
Quick Check:
Missing integration = A [OK]
Hint: Install framework integrations to enable client:only usage [OK]
Common Mistakes:
Forgetting to install Vue integration
Thinking Astro doesn't support Vue
Confusing client:load with client:only
5. You want to create a page with three islands: a React form, a Svelte chart, and a Vue button. How should you configure these islands in Astro for best performance?
hard
A. Load all frameworks globally in the main layout and use islands without client directives
B. Use client:load on all islands without specifying frameworks
C. Use React component with client:load, Svelte component with client:load, and Vue component with client:load on each island and install all three integrations
D. Use only one framework for all islands to avoid multiple integrations
Solution
Step 1: Identify the best practice for multiple frameworks
Astro allows multiple frameworks per page by using components from each framework with client:load (or other) on each island and installing needed integrations.
Step 2: Avoid loading all frameworks globally or using client:load without framework
Loading all globally wastes resources; use per-island components.
Step 3: Choose the correct approach
Configure React form with client:load, Svelte chart with client:load, Vue button with client:load, with integrations for best performance.
Final Answer:
Use React component with client:load, Svelte component with client:load, and Vue component with client:load on each island and install all three integrations -> Option C
Quick Check:
Multiple frameworks per island = D [OK]
Hint: Use client:load with all needed integrations for multiple islands [OK]
Common Mistakes:
Loading all frameworks globally wasting resources
Using client:load without specifying framework
Trying to use only one framework for all islands
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.