client:load in Astro?Consider an Astro component that uses client:load to load a React component. What is the behavior of the React component in the browser?
--- import MyReactComponent from '../components/MyReactComponent.jsx'; --- <MyReactComponent client:load />
Think about when client:load triggers the loading of client-side JavaScript.
The client:load directive tells Astro to wait until the page HTML is fully loaded in the browser before loading and hydrating the component. This means the React component is not rendered on the server but only after the client loads the page.
client:load in AstroWhich of the following is the correct way to apply the client:load directive to a component in Astro?
Astro directives use colon syntax, not camelCase or underscores.
The correct syntax for Astro client directives uses a colon, so client:load is valid. Variations like camelCase or underscores are invalid.
client:load fail to hydrate?Given this Astro code, the React component does not hydrate on the client. What is the most likely cause?
--- import ReactComponent from '../components/ReactComponent.jsx'; --- <ReactComponent client:load></ReactComponent>
Check the React component export style.
If the React component does not have a default export, Astro cannot import it properly, causing hydration to fail. The client:load directive works with React components if imported correctly.
client:load in Astro?Consider a React component with internal state rendered using client:load in Astro. When does the state initialize and how does it behave?
--- import Counter from '../components/Counter.jsx'; --- <Counter client:load />
Think about when React hooks run in client-side rendering.
With client:load, the React component is hydrated only after the page loads in the browser. The state initializes then, starting at the initial value and updating normally on user interaction.
client:load over client:idle or client:visible in Astro?Which reason best explains when client:load is the preferred directive for loading client-side components in Astro?
Consider the timing of when the component becomes interactive.
client:load loads the component's JavaScript and hydrates it as soon as the page finishes loading, making it ideal for components that need to be interactive immediately after load but without blocking server rendering.