Think of it like you're just calling JavaScript functions. You can't use a for loop where the arguments to a function call would go:

return tbody(
    for (let i = 0; i < numrows; i++) {
        ObjectRow()
    } 
)

See how the function tbody is being passed a for loop as an argument – leading to a syntax error.

But you can make an array, and then pass that in as an argument:

const rows = [];
for (let i = 0; i < numrows; i++) {
    rows.push(ObjectRow());
}
return tbody(rows);

You can basically use the same structure when working with JSX:

const rows = [];
for (let i = 0; i < numrows; i++) {
    // note: we are adding a key prop here to allow react to uniquely identify each
    // element in this array. see: https://reactjs.org/docs/lists-and-keys.html
    rows.push(<ObjectRow key={i} />);
}
return <tbody>{rows}</tbody>;

Incidentally, my JavaScript example is almost exactly what that example of JSX transforms into. Play around with Babel REPL to get a feel for how JSX works.

Answer from Sophie Alpert on Stack Overflow
🌐
Telerik
telerik.com › blogs › beginners-guide-loops-in-react-jsx
A Beginner’s Guide to Loops in React JSX
August 18, 2022 - Wondering how to create loops in React? Learn about JSX and how to use methods like the map function to loop inside React JSX and render a list of items.
🌐
Reddit
reddit.com › r/reactjs › can i use a for loop with jsx? to render something 3 times?
r/reactjs on Reddit: Can I use a for loop with JSX? To render something 3 times?
August 31, 2021 -
let sampleOutput =()=>{
  return
    for(let i=0;i<3;i++){<p>hi</p>}  
}


trying to display hi 3 times inside

return()

in my component. I know how to .map or .forEach for objects and arrays but what if my store or variable is just a number, I assume forloop doesnt work?

🌐
Sentry
sentry.io › sentry answers › react › how do you loop inside react jsx?
Loop Inside JSX Using For Loops or the map() Method | Sentry
2 weeks ago - If you have a set of elements, you can use normal JavaScript for, for of, and for in loops outside the return block. Inside the return block, you can use the resulting array. You can loop over an array and create JSX partials like so: import React from "react"; function App() { const seasons = ["Spring", "Summer", "Autumn", "Winter"]; let seasonsList = []; seasons.forEach((season, index) => { seasonsList.push(<li key={index}>{season}</li>); }); return ( <div> <h2>Seasons of the year</h2> <ul>{seasonsList}</ul> </div> ); } export default App;
🌐
GeeksforGeeks
geeksforgeeks.org › reactjs › loop-inside-react-jsx
Loop Inside React JSX - GeeksforGeeks
August 5, 2025 - In this approach, a traditional for loop is used within JSX to dynamically render colored div elements based on the colors array. The loop iterates through the colors array, generating div elements with inline styling for each color. Users can add new colors to the list using the approach2Fn function, demonstrating dynamic rendering and user interaction within a React component.
🌐
Medium
medium.com › frontendweb › how-to-use-loops-in-react-js-4953cc2ff0c7
How to use loops in React.js?
December 25, 2022 - It take time create or recreate app with for and while loop. You can use forEach() directly in reactjs.
🌐
Angular Minds
angularminds.com › blog › a-guide-on-how-to-use-for-loop-in-react
A Guide on How to Use For Loop in React
August 27, 2024 - In React, directly using traditional loops like for within JSX is not possible due to JSX’s requirement for a single expression. Instead, developers commonly use the map function to iterate over arrays and render a list of elements.
🌐
CoreUI
coreui.io › blog › how-to-loop-inside-react-jsx
How to loop inside React JSX · CoreUI
September 27, 2024 - This guide will cover the different ways to render lists and elements using loops in React, focusing on the use of the map function, traditional loops, and best practices. Let’s explore how to create components dynamically and render lists efficiently using React JSX. ... JSX (JavaScript XML) is a JavaScript syntax extension that allows you to write HTML-like code within JavaScript files. However, normal JavaScript constructs, like for loops, aren’t directly supported within JSX because they are statements, not expressions.
Find elsewhere
🌐
Medium
medium.com › @angularminds › a-guide-on-how-to-use-for-loop-in-react-f6d58329e56d
A Guide on How to Use For Loop in React | by Angular Minds | Medium
August 27, 2024 - JSX and for Loops: Directly using for loops within JSX is not recommended due to JSX’s requirement for a single expression. The map() Function: For rendering arrays as components in React, the map function is the preferred approach.
🌐
Upmostly
upmostly.com › home › tutorials › how to for loop in react (with examples)
How to Use For Loop in React (with Code Examples)
October 28, 2021 - Out of the three iterators above, our best option to iterate over an array in React inside of JSX is the Map function. Let’s begin by exploring how we can use the Map iterator to loop through elements in an array and render out some HTML for each of those elements.
🌐
iFour Technolab
ifourtechnolab.com › blog › loops-in-react-jsx-a-deep-dive-into-the-basics
Loops in React JSX: A deep dive into the basics | iFour Technolab
October 20, 2022 - You may have observed that we did not generate li elements 5 times. We iterated the array with a map, and the map returned the new element. The output will be as follows: Figure 2. using the map Method ... Users can use the standard “for” loop for creating the li element.
🌐
Medium
medium.com › @pooya.oladazimi › 4-for-loops-in-react-js-ca11b781cf5b
4 For Loops in React/JS. This post was originally published at… | by Pooya Oladazimi | Medium
July 9, 2023 - This for-loop works exactly like Type1. However, here the syntax is less complex. The idea is we write a loop that on each iteration takes one of the list members in order. We just need a variable to assign each list object to it on each iteration.
🌐
ACTE
acte.in › home › how to use for loop in react: a comprehensive guide
How to Use For Loop in React: Quick Guide | Updated 2026
CyberSecurity Framework and Implementation Article - Learn How to Use For Loopin React to Efficiently Render Lists and Elements. This Quick Guide Covers Syntax, Best Practices, Real-World Examples, and Tips. One of best Institute to learn CyberSecurity Framework and Implementation from ACTE . Really impressive model where you can learn technical Skills , Soft Skill and get help to kick start your first Job as well.
Rating: 5 ​
🌐
GitHub
github.com › MJez29 › react-for
GitHub - MJez29/react-for: A React component library to create loops in JSX · GitHub
import { For } from 'react-for'; <For start={INITIAL_VALUE} comparator={i => TEST_EXPR} next={i => NEXT_OP}>{ (i) => { CODE_TO_CREATE_COMPONENT; return component; } }</For> The ForOf component emulates a for..of loop.
Author: MJez29
🌐
Educative
educative.io › answers › how-to-implement-a-component-loop-in-react
How to implement a component loop in React
Let’s run the same example of looping through components using forEach() loop. import React from 'react'; function ListItem(props) { return <li>{props.text}</li>; } export default ListItem;
🌐
Medium
medium.com › @rana.adnanali › how-to-write-for-loop-in-react-js-83ef4f67d9f7
How to Write for Loop in React JS | by Rana Adnan | Medium
August 8, 2023 - This helps React identify which items have changed, improving rendering efficiency. Nested loops involve placing one loop inside another. While they can be useful, they require careful handling to avoid performance issues. Loops can also be combined with conditional statements to render components conditionally based on data. When using loops to render components, event handling becomes a consideration. It’s important to handle events correctly for each rendered component.
🌐
freeCodeCamp
forum.freecodecamp.org › t › for-loops-ever-in-react › 346935
For loops ever in React? - The freeCodeCamp Forum
February 3, 2020 - { let spans = [] for (let i = 0; i ) } return spans } export default SpanMaker I think another thing to note here is that I am not updating...
🌐
Intellipaat
intellipaat.com › home › blog › how to use for loop in react? (with examples)
How to Use For Loop in React? (With Examples) | Intellipaat
April 15, 2025 - You can use a for loop in React using the map() method on the array. The for loop allows you to repeat a code block for a specific number of times.