How to extract props from styled component #64
Unanswered
dominictobias
asked this question in
Q&A
Replies: 1 comment
-
|
To get type of props for any React component (not only when using macaron-css) you can use type StyledButtonProps = React.ComponentProps<typeof StyledButton>then, to get type of each variant (as you asked for in your question) you can use: type ColorProp = StyledButtonProps['color']
// ^? type ColorProp = "neutral" | "brand" | "accent" | undefined
type RoundedProp = StyledButtonProps['rounded']
// ^? type RoundedProp = boolean | undefined |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Taking the example:
How can we extract the props
rounded,color, andsizeinto a type, so that we could mix in other props that our component might want? (In the case that we have a wrapping component which performs additional logic/rendering, but we still want the end user to get these props, which will will pass through)I thought typeof but I'm getting a confusing error that no types overlap:
Beta Was this translation helpful? Give feedback.
All reactions