Consider this Astro file importing a React component. What will be rendered on the page?
/* Astro file: Example.astro */ --- import Counter from './Counter.jsx'; --- <html lang="en"> <body> <Counter client:load start={5} /> </body> </html> /* React component: Counter.jsx */ import React, { useState } from 'react'; export default function Counter({ start }) { const [count, setCount] = useState(start); return ( <button onClick={() => setCount(count + 1)} aria-label="Increment count"> Count: {count} </button> ); }
Think about how props are passed from Astro to React components and how React state initializes.
The React component Counter receives the start prop with value 5 from Astro. It uses this as the initial state for count. The button shows 'Count: 5' initially and increments on click.
Choose the correct Astro syntax to import and render a React component named MyButton from ./MyButton.jsx.
Astro imports React components as default exports and uses JSX syntax directly.
Option D correctly imports the default export and uses it as a JSX tag. Option D tries named import which is invalid if MyButton is default export. Options A and C use invalid Astro syntax for React components.
Given a React component used in Astro with client:load directive, when does the React component mount?
<!-- Astro file snippet --> <MyComponent client:load />
Recall what client:load means in Astro for React components.
client:load tells Astro to render static HTML first, then hydrate and mount the React component immediately after the page loads in the browser.
Astro renders this React component, but React hydration fails with a mismatch error. What is the likely cause?
/* React component Counter.jsx */ import React, { useState } from 'react'; export default function Counter() { const [count, setCount] = useState(Math.floor(Math.random() * 10)); return <div>Count: {count}</div>; } /* Astro file */ --- import Counter from './Counter.jsx'; --- <Counter client:load />
Think about what happens when server and client render different initial HTML.
Using random value in useState means server renders one number, client another. This mismatch breaks React hydration.
Astro supports partial hydration of React components. Which statement best describes this behavior?
Consider how Astro optimizes loading by hydrating only parts that need interactivity.
Astro sends static HTML for the page and hydrates only React components marked with client directives like client:load or client:idle, reducing JavaScript load and improving speed.