G
G
GreenMan18992019-04-28 22:50:10
React
GreenMan1899, 2019-04-28 22:50:10

How to output other components passed as props to the component?

I pass the Header and Footer components to the Layout component and want to display them inside it.
How to do it right?
Now the functions of these components are passed to the console.log that is called in the layout, but nothing appears in the render.
5cc603f16508e723931654.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Proskurin, 2019-04-28
@GreenMan1899

Your Header is a component, not an element (instance). Therefore, getting it from props, you get a regular component that you draw in a standard way.

const { Header, Footer } = this.props;

return (
    <Fragment>
        <Header />
        <Footer />
     </Fragment>
);

But it is better to pass not a component, but a render function https://reactjs.org/docs/render-props.html.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question