API for getting all kamForms data
router.get('/kam', (req, res) => {
kamForm
.find()
.then((result) => {
res.status(200).json({
kamData: result,
});
})
.catch((err) => {
console.log(err);
res.status(500).json({
message: err,
});
});
});
And this is the API call and rendering part, when I inspect the browser all the data is showing in the console repeatedly. I will attach the ss of the console.
const PendingApplication = () => {
const [data, setData] = useState([]);
useEffect(() => {
axios
.get('http://localhost:5000/api/kam')
.then((response) => {
console.log(response);
setData(response.data);
})
.catch((error) => {
console.log(error);
});
});
return (
<div>
<Table>
<TableBody>
{[data].map((item, index) => (
<TableRow key={index}>
<TableCell>{item.kcpname}</TableCell>
<TableCell>{item.companyname}</TableCell>
<TableCell>{item.ticketno}</TableCell>
<TableCell>{item.totalemp}</TableCell>
<TableCell>{item.kcpnid}</TableCell>
<TableCell>{item.kcpcontact}</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</div>
);
};