Sultan Zhumatayev Sultan Zhumatayev - 4 years ago 110
React JSX Question

loop adding compenent in reactjs

how to add component card in loop?
how to do it in right way?
All snipet here https://jsfiddle.net/oL1gawfo/

...
for(let i=1;i<5,i++){
var colorhex="#FFA"+i+"56";
ReactDOM.render(
<div>
<Card color=colorhex/>
</div>,
document.querySelector("#c"+i)
);
}
...

Answer Source

i just found another way.

var colors = ["#393E41", "#E94F37", "#1C89BF", "#A1D363",
              "#85FFC7", "#297373", "#FF8552", "#A40E4C"];

var renderData = [];

for (var i = 0; i < colors.length; i++) {
  renderData.push(<Circle bgColor={colors[i]}/>);
}

ReactDOM.render(
  <div>
    {renderData}
  </div>,
  destination
);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download