I am getting error: " Cannot read properties of undefined (reading '__H')" at this code:…
- User
I am getting error: " Cannot read properties of undefined (reading '__H')" at this code: "--- import { Picture } from "@astrojs/image/components"; import type { ShowcaseSite } from "~/types"; import { useState } from 'preact/hooks';
export interface Props { site: ShowcaseSite; }
const { site } = Astro.props;
const widths = [450, 800]; const sizes = "(min-width: 1024px) 33vw, (min-width: 768px) 50vw, 100vw"; const [isModalOpen, setIsModalOpen] = useState(false); const openModal = () => { setIsModalOpen(true); };
code<!--<p class="border border-current px-4 py-2">{site.url}</p>--> </div> </figcaption> </figure> - Assistant
The error is due to mixing Astro and Preact code. In Astro components, you cannot use Preact or React hooks directly. To fix the issue we can create a separate Preact component to handle the state, and then render that Preact component inside the Astro component.
Astro Component:
astro - User
I got error: "Invalid arguments passed to component. Astro components cannot be rendered directly via function call, such as Component() or {items.map(Component)}."
- Assistant
Apologies for the confusion. The error occurs because the
Picturecomponent from@astrojs/image/componentsis an Astro component, and it cannot be used directly inside a Preact component. To fix this issue, you can create a separate Astro component for the and then use it inside the Preact component using the method. - User
instead use slot
- Assistant
You can use a slot to pass the
Picturecomponent from the Astro component to the Preact component. Here's how you can do it:Update the
ShowcaseCard.jsPreact component to accept a slot:jsx