|
I have component that copies the text passed to it - When I invoke it, how to pass a styled component to it, or is there another way of doing it? |
Answered by
quantizor
Mar 21, 2026
Replies: 2 comments
|
@salimabsi You can try some of this ways: const Parent = () => {
return (
<Child childComp={<YourCompToPass />} />
)
};
const Child = (props) => {
return (
<>
{props.childComp}
</>
)
}Or using const Parent = () => {
return (
<Child>
<YourCompToPass />
</Child
)
};
const Child = (props) => {
return (
<>
{props.children}
</>
)
} |
0 replies
|
Styled components are regular React components, so you can pass them as props like any other component: <CopyText TextComponent={MyStyledText} />Then render it inside const CopyText = ({ TextComponent, children }) => (
<TextComponent>{children}</TextComponent>
);This is standard React composition and is not specific to styled-components. |
0 replies
Answer selected by
quantizor
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment


Styled components are regular React components, so you can pass them as props like any other component:
Then render it inside
CopyText:This is standard React composition and is not specific to styled-components.