How to pass props to components #129
-
Hey, thanks so much for your library @theisel. I'm passing my own custom ListItem component to the PortableText component, shown below.
Is there a way to pass props to the component you match up to the listItem? I've tried doing it like this Is there a way to pass props to components with this library? Thank you for your time! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hi @LushawnDev, I suggest making a Refer also to extending ListItem. /* PortableTextListItem */
---
import type { Props as $, ListItem } from "astro-portabletext/types";
import Li from "path/to/ListItem.astro";
export type Props = $<ListItem>;
const { node } = Astro.props;
const liProps = {
listItem: node.listItem,
};
---
<Li {...liProps}>
<slot />
</Li> /* ListItem */
---
export type Props = {
listItem: string;
};
// Do something with listItem prop
---
<li><slot /></li> |
Beta Was this translation helpful? Give feedback.
-
Hi @LushawnDev have you managed to resolve your issue? |
Beta Was this translation helpful? Give feedback.
Hi @LushawnDev, I suggest making a
PortableTextListItem
and a genericListItem
component.Refer also to extending ListItem.