Can you use a for
loop in JSX like this?
Or rather, what is the propper way to write a for
like this?
var graph =
.
.
.
{DataRows.forEach(function(entry) &&
entry
)}
;
Answer
Use a map so you're actually returning the elements. A foreach doesn't return anything. Your use of &&
was also invalid.
var graph =
{DataRows.map(entry =>
entry
)}
;
Note that I added a key
property - for react to optimise rendering of an array of elements each item should have a unique key (that isn't just the numeric index).
No comments:
Post a Comment