Skip to content
FLAVIO COPES
flaviocopes.com
2026

How to repeat displaying something in JSX

By Flavio Copes

Learn how to repeat something in JSX, like rendering a number of stars from a rating value, using the [...Array(n)].map() spread array trick.

~~~

I had the need to repeat something in JSX.

The use case was this, I had a review expressed from 1 to 5 and based on the value I wanted to display some stars, from 1 to 5 stars.

So I used this snippet:

<p>
{[...Array(rating)].map(() => '⭐️ ')}
</p>
Tagged: React · All topics
~~~

Related posts about react: