Reputation: 844
I want to return multiple <li>
tags from my component's render()
method, however React enforces you to have a single parent, which could be </>
.
I'm performing some logic with element's parent, so I cannot have a parent for these <li>
elements; <ul>
for <li>
elements is in another component and it cannot be moved.
So how can I return multiple <li>
elements from my component? Thanks.
Upvotes: 0
Views: 184
Reputation: 151
You can return an array of elements too in React.
return ([<div />,<div />,<div/>])
Upvotes: 1
Reputation: 1767
React Fragment
return (
<>
<li/>
<li/>
</>
)
or
return (
<React.Fragment>
<li />
<li />
</React.Fragment>
)
For more details https://reactjs.org/docs/fragments.html
Upvotes: 3
Reputation: 525
Try:
return (
<React.Fragment>
<li />
<li />
</React.Fragment>
)
Upvotes: 1