Skip to content

How to pass props to components #129

Closed Answered by theisel
LushawnDev asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @LushawnDev, I suggest making a PortableTextListItem and a generic ListItem component.

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>

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by LushawnDev
Comment options

You must be logged in to vote
2 replies
@LushawnDev
Comment options

@theisel
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants