import React from 'react';
function App() {
const myArray = ['Ranjeet', 'Adil', 'Preet'];
return (
<div className="container" style={{background:'red'}}>
<h1> Example of React Map Loop </h1>
{myArray.map(name => (
<li>
{name}
</li>
))}
</div>
);
}
export default App;
You need to pass an array of element to jsx.
The problem is that forEach does not return anything (i.e it returns undefined).
So it's better to use map because map returns an array:
***