Answer the question
In order to leave comments, you need to log in
How to correctly pass another component as a prop?
I get the error Objects are not valid as a React child (found: object with keys {$$typeof, type, compare}). If you meant to render a collection of children, use an array instead.
const Header = props => (
<div className="navHeader">
{props.top}
</div>
);
export const Top = React.memo(props => (
<div className="top">
<div className="site-identifier">
<Logo />
<Link to="/">
Привет
</Link>
</div>
{props.children}
</div>
));
import Header, { Top } from "./views/header";
<Header top={Top}/>
Answer the question
In order to leave comments, you need to log in
Consider the option:
const Header = ({ children }) => (
<div className="navHeader">
{children}
</div>
);
<Header>
<Top />
</ Header>
const Header = ({ top }) => {
const HeaderTop = top || Top;
return (
<div className="navHeader">
<HeaderTop />
</div>
);
};
<Header top={OtherTopCompnent} /> // используем другой компонент
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question