React Answers

How to add loop with React JSX?

Spread the love

To add loop with React JSX, we use the array map method.

For instance, we write

  {[...Array(10)].map((x, i) => (
    <ObjectRow key={i} />

to render the array’s data by creating array with 10 entries with Array(10).

Then we call map with a callback that returns the ObjectRow component to render its contents.

We set the key prop to i to set a unique key for each item.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *