Skip to content

How to inject children? #153

Discussion options

You must be logged in to vote

If you are using shadow mode (open or closed, doesn't matter), this is very easy to do with slots. If you only need the one slot, using it like you would use children in React, a simple wrapper component is perfect (the same as I suggested in your Enum question. I find myself using this pattern a lot). If you have more than one or want to set up defaults and overrides, I'd suggest reading more about slots at MDN.

const WebPill: React.FC = ({ ...props }) => {
  return <Pill {...props}><slot /></Pill>
})

In a shadowed web component, <slot /> will automatically render the children of the web-component in this spot. React will never know what they are, it only sees the slot element, but the b…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by christopherjbaker
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