I am trying to display 5 input fields on the screen within a for loop. I also want to apply a dynamic class to each of them later (according to their state). Here is my code:
function App() {
...
return (
<Grid container className={classes.root}>
<CssBaseline />
<Grid item xs={false} md={7} className={classes.image} />
<Grid item xs={12} md={5} component={Paper} elevation={6} square>
<div className={classes.paper}>
<form className={classes.form} onSubmit={handleSubmit}>
{inputFields}
for (let i = 0; i < 5; i++) {
<TextField />
}
{for (let i = 0; i < 5; i++) {
<TextField />
}}
<Button
type="submit"
fullWidth
variant="contained"
color="primary"
className={classes.submit}
>
Submit
</Button>
</form>
</div>
</Grid>
</Grid>
);
}
Here is the error I am getting: SyntaxError: Unexpected token.
I am still learning React, so I am pretty sure I am doing it wrong. How does one render multiple elements with a for loop? Is there a better way?
Thanks!


for(){}is JS code. To embed JS code in JSX, you must put it inside two curly braces such as:{for (){}}forloop does not work