Want to repeat an element n times using JSX in your ReactJS application? Use the below example:
1 2 3 4 | let card = []; _.times(8, () => { card.push(<span className="busterCards">♦</span>); }); |
You may want to add key to each span element so React won’t complain about missing the key attribute:
1 2 3 4 | let card = []; _.times(8, (i) => { card.push(<span className="busterCards" key={i}>♦</span>); }); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.