0
0
Astroframework~5 mins

React components in Astro - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the main purpose of using React components inside an Astro project?
React components let you add interactive UI parts inside Astro, which mainly builds static sites. This way, you get the best of both: fast static pages and dynamic React features.
Click to reveal answer
beginner
How do you import a React component into an Astro file?
Use the syntax: <code>import MyComponent from './MyComponent.jsx';</code> at the top of your Astro file. Then you can use <code>&lt;MyComponent /&gt;</code> inside your Astro template.
Click to reveal answer
intermediate
What is the role of the client:load directive when using React components in Astro?
The client:load directive tells Astro to load and run the React component only on the browser after the page loads. This makes the component interactive without slowing down the initial page load.
Click to reveal answer
intermediate
Can you explain the difference between client:load and client:idle in Astro React components?
client:load loads the React component as soon as the page loads. client:idle waits until the browser is idle before loading the component, improving performance by delaying less important scripts.
Click to reveal answer
beginner
Why is it important to use React components only where interactivity is needed in Astro?
Because React components add JavaScript to the page, using them only when needed keeps the site fast and lightweight. Astro’s strength is static content, so limiting React helps maintain speed and good user experience.
Click to reveal answer
How do you make a React component interactive in Astro?
AAdd <code>client:load</code> to the component tag
BImport it with <code>import React from 'react'</code>
CWrap it in a <code>&lt;script&gt;</code> tag
DUse <code>server:only</code> directive
Where do you write the import statement for a React component in an Astro file?
AAt the top of the Astro file
BInside the component JSX code
CInside a <code>&lt;script&gt;</code> tag in HTML
DYou don't need to import React components
What happens if you don't add any client directive to a React component in Astro?
AThe component will be interactive by default
BAstro will throw an error
CThe component will load twice
DThe component will render static HTML only, no interactivity
Which client directive delays loading a React component until the browser is idle?
Aclient:load
Bclient:visible
Cclient:idle
Dclient:media
Why might you choose to use React components inside Astro instead of pure Astro components?
ABecause Astro does not support HTML
BTo add interactive features like buttons or forms
CTo make the site load slower
DTo avoid using JavaScript
Describe the steps to add a React component to an Astro page and make it interactive.
Think about import, usage, and client directives.
You got /3 concepts.
    Explain why Astro uses client directives like client:load or client:idle when working with React components.
    Consider how loading timing affects user experience.
    You got /4 concepts.