-
|
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? |
Beta Was this translation helpful? Give feedback.
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}
</>
)
} |
Beta Was this translation helpful? Give feedback.
-
|
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. |
Beta Was this translation helpful? Give feedback.


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.