I have created a mega menu where the values will be dynamic (coming from the API). So you never know how many links will be there. But for testing purpose I've put 50 texts in array menu and trying to loop over that so that it look Like this . So there's a parent row and inside that there are 5 columns, each containing 5 links. Per row will contain 5 columns or 25 links.
JSX
const menu = [
"one",
"two",
"three",
"four",
"five",
"one",
"two",
"three",
"four",
"five",
... (total 50)
];
<Box className={classes.rows}>
<Box className={classes.cols}>
<Typography variant="body1" className={classes.link}>
Link 1
</Typography>
<Typography variant="body1" className={classes.link}>
Link 1
</Typography>
<Typography variant="body1" className={classes.link}>
Link 1
</Typography>
<Typography variant="body1" className={classes.link}>
Link 1
</Typography>
<Typography variant="body1" className={classes.link}>
Link 1
</Typography>
</Box>
<Box className={classes.cols}>
<Typography variant="body1" className={classes.link}>
Link 1
</Typography>
<Typography variant="body1" className={classes.link}>
Link 1
</Typography>
<Typography variant="body1" className={classes.link}>
Link 1
</Typography>
<Typography variant="body1" className={classes.link}>
Link 1
</Typography>
<Typography variant="body1" className={classes.link}>
Link 1
</Typography>
</Box>
<Box className={classes.cols}>
<Typography variant="body1" className={classes.link}>
Link 1
</Typography>
<Typography variant="body1" className={classes.link}>
Link 1
</Typography>
<Typography variant="body1" className={classes.link}>
Link 1
</Typography>
<Typography variant="body1" className={classes.link}>
Link 1
</Typography>
<Typography variant="body1" className={classes.link}>
Link 1
</Typography>
</Box>
<Box className={classes.cols}>
<Typography variant="body1" className={classes.link}>
Link 1
</Typography>
<Typography variant="body1" className={classes.link}>
Link 1
</Typography>
<Typography variant="body1" className={classes.link}>
Link 1
</Typography>
<Typography variant="body1" className={classes.link}>
Link 1
</Typography>
<Typography variant="body1" className={classes.link}>
Link 1
</Typography>
</Box>
<Box className={classes.cols}>
<Typography variant="body1" className={classes.link}>
Link 1
</Typography>
<Typography variant="body1" className={classes.link}>
Link 1
</Typography>
<Typography variant="body1" className={classes.link}>
Link 1
</Typography>
<Typography variant="body1" className={classes.link}>
Link 1
</Typography>
<Typography variant="body1" className={classes.link}>
Link 1
</Typography>
</Box>
</Box>
I tried using for loop and then create another 2D array. And later planned to map through that array inside JSX.
let links = [];
if (menu.length != 0) {
for (let i = 0; i < menu.length; i++) {
for (let j = 0; j < 5; j++) {
links.push(menu[i]);
}
}
}
But it won't work I know. Can anyone help me with this?
