Sometimes, we want to render repeating React elements.
In this article, we’ll look at how to render repeating React elements.
How to render repeating React elements?
To render repeating React elements, we use the array map method.
For instance, we write
<table>
{[...Array(3)].map((_, index) => (
<tr key={index} />
))}
</table>;
to call map on an array with a callback that returns tr elements.
We set the key prop to a unique value so React can identify each item rendered.
Conclusion
To render repeating React elements, we use the array map method.