I can pass a styled-component(Text
component) like
export const Text = styled.span`
font-size: 16px;
color: red;
`;
Text.displayName = 'Text';
const Parent = () => {
return (
<>
<Child Text={Text} />
</>
);
};
but now like this
<Child Text={<Text />} />
I get an error: Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
Is there a way to pass Text
component like this <Child Text={<Text />} />
?
2
Answers
Yes, but you have to render it like this:
No, in your example "Text" is not a react component but a mere object. A react component is declared as a function. For example: