I have a problem regarding my code where I can not output the mapping into 6 columns in the table. So what I want is that whenever the data reach 6 columns it will create a new row. Below is my code:
import React from "react";
import { useEffect, useState } from "react";
import timestamp from "unix-timestamp";
export const Result = (code) => {
const [output, setOutput] = useState([]);
const [time, setTime] = useState([]);
const [data, setData] = useState([]);
const [hari, setHari] = useState([]);
useEffect(() => {
getWaktuSolat();
outputList();
setData([]);
}, [code.code]);
var requestOptions = {
method: "GET",
redirect: "follow",
};
async function getWaktuSolat() {
await fetch("https://mpt.i906.my/api/prayer/" + code.code, requestOptions)
.then((response) => response.json())
.then((result) => {
console.log(result.data);
setOutput(result.data);
setTime(result.data.times);
console.log(time);
})
.catch((error) => console.log("error", error));
}
function outputList() {
for (let x = 0; x < time.length; x++) {
for (let z = 0; z < 6; z++) {
let j = timestamp.toDate(time[x][z]);
data.push(j.toString().slice(15, 21));
console.log(data);
}
}
}
outputList();
return (
<div className="Result">
<h1>{output.place}</h1>
<table>
<th>Subuh</th>
<th>Syuruk</th>
<th>Zuhur</th>
<th>Asar</th>
<th>Maghrib</th>
<th>Isyak</th>
<tr>
{data.map((item, index) => (
<td>{item}</td>
))}
</tr>
</table>
</div>
);
};
export default Result;
This is my output