A
A
Anya Kolomenskaya2020-09-03 17:52:12
React
Anya Kolomenskaya, 2020-09-03 17:52:12

How to output multiple child components without a wrapper in a React component?

Let's say we have an ArticleContent React component that outputs

<div>
    <h3></h3>
    <p class="primary-text"></p>
    <p class="additional-text"></p>
</div>

But here the div only acts as a "wrapper" for the content and generally clutters up the layout. Is there a way to get rid of this limitation of a React component to render only one element?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2020-09-03
@Anya_Koya

react.fragment

B
Bektur Muratov, 2020-09-03
@prosto_paren

It is possible like this:

<>
    <h3></h3>
    <p class="primary-text"></p>
    <p class="additional-text"></p>
</>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question