Loop inside React JSX?

Answer

how the function tbody is being passed a for loop as an argument – leading to a syntax error.

So you can make an array, and then pass that in as an argument:

var rows = [];
for (var i = 0; i < numrows; i++) {
rows.push(ObjectRow());
}

return tbody(rows);

You can basically use the same structure when working with JSX:
var rows = [];
for (var i = 0; i < numrows; i++) {
// note: we are adding a key prop here to allow react to uniquely identify each
// element in this array. see: https://reactjs.org/docs/lists-and-keys.html
rows.push(<ObjectRow key={i} />);
}
return <tbody>{rows}</tbody>;

All react js Questions

Ask your interview questions on react-js

Write Your comment or Questions if you want the answers on react-js from react-js Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---