A
A
Anya Kolomenskaya2020-09-03 17:41:45
React
Anya Kolomenskaya, 2020-09-03 17:41:45

How to give a place for content to a React component?

Let's say we have a SectionContainer React component that renders

<section>
    <h3></h3>
    <article></article>
    <div></div>
</section>

And it is used in the following form:
<SectionContainer>
    <SectionContent />
    <SectionExtraContent />
</SectionContainer>

How do I tell the SectionContainer that the content should be inserted inside the article 'I', and not in the h3 or div 'a?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hzzzzl, 2020-09-03
@Anya_Koya

https://reactjs.org/docs/composition-vs-inheritanc...

// если это классовый компонент, а не функция
<section>
    <h3></h3>
    <article>{this.props.children}</article>   
    <div></div>
</section>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question