Answer the question
In order to leave comments, you need to log in
How to make render without div, react?
Good afternoon! Who knows how to render without using react in this case div
?
In react 16 there is a Fragment for this, but now I have a lower version.
Who knows how to do it?
const Item= ({ list}) => (
<div>
{list.map(li=> (
<p key={li}>{li} </p>
))}
</div>
);
const Item = ({ list}) => list.map(li=> <p key={li}> {li}</p>);
A valid React element (or null) must be returned. You may have returned undefined, an array or some other invalid object.
Answer the question
In order to leave comments, you need to log in
const Item = ({ list }) => (
<React.Fragment>
{list.map(li => <p key={li}>{li}</p>)}
</React.Fragment>
);
const Fragment = ({ children }) => children;
const Item = ({ list }) => (
<Fragment>
{list.map(li => <p key={li}>{li}</p>)}
</Fragment>
);
Fragment is optional, just like div. just need to return one main container, it can be or or etc.
your error says that in map you need to do return:
const Item = ({ list}) => list.map(item => return { item });
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question