0

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)
          );
        }
  ...

2 Answers 2

1

The syntax of your for loop is incorrect. You need ; to separate your for loop expressions and not a comma

for(let i=1;i<5;i++){

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

JSFIDDLE

Sign up to request clarification or add additional context in comments.

Comments

0

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
);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.