I am new to React and wanted to use forEach loop in JSX but no result. Here is the code:
class Car extends React.Component {
render() {
let list = ["Thing one", "Thing Two", "Thing Three"];
return (
<div>
{list.forEach(function(item) {
<h1>{item}</h1>;
})}
</div>
);
}
}
const box = document.querySelector(".mir");
ReactDOM.render(<Car list />, box);
{Thing one}
", "{Thing two}
", "{Thing three}
"] Is that correct? if so, then how does renderer understands to put each element of that new array into respective h1 element. Again we got new array from map() and how does computer or renderer understand to separate each and put into respective array – mobi Aug 18 '19 at 12:17