-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🐛 BUG: Can't pass astro template to component as a prop. #3964
Comments
Thanks for opening an issue! This is an intentional limitation of our compiler, though I'm sure we could provide a better error message here. Instead of passing elements in as props, you should pass the elements as children and use the <Post>
<span slot="header">this is passed as `header`</span>
<p>this works fine</p>
<SomeOtherCompoenent slot="footer" />
</Post> https://stackblitz.com/edit/github-at2rbu-9xff7k?file=src%2Fpages%2Findex.astro |
Oh nice, I had no idea that slots worked this way. |
Maybe I need to open a new issue for this, but how can I pass a component to a React component in an Astro template? In other words, I have an Astro component that includes a React component, and I'd like to pass some custom component into that React component, but from within the Astro component. I can't use slots right because the React component is where my custom component is going to be rendered. |
I would not make this behavior intentional, but rather a concede that the parser is incomplete. Properties are both typed and non-opaque values, whereas slots - unless I'm missing something - provide outlets to pass content through opaquely. Here's a simple case.
To not support this intentionaly is surprising. |
Pardon for necro-bumping, but here's a more detailed explanation from the maintainers, for those interested. |
What version of
astro
are you using?1.0.0-beta.72
Are you using an SSR adapter? If so, which one?
doesn't apply
What package manager are you using?
pnpm
What operating system are you using?
Windows 10
Describe the Bug
Astro template can't be passed to an island component property, but it can be passed as children.
This could cause a weird situation where I'm not able to set a certain prop in the
.astro
files, and I have to create a.tsx
wrapper, only to be able to pass jsx to an island.But such a workaround prevents the ability to granularly set, or not set the
client:
directives. You can only control the wrapper hydration.I'm using Solid, but I guess this applies to any framework as it's the compiler issue.
This is probably a known issue, but I'm just curious if this is something that could be fixed in the future.
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-at2rbu?file=src%2Fpages%2Findex.astro
Participation
The text was updated successfully, but these errors were encountered: