patients.users it's an array of objects but I cannot loop through it. When I was trying to call patients.users[0] it returned "TypeError: Cannot read properties of undefined (reading '0')". Why is that?
function DoctorPanel() {
const location = useLocation();
const { id } = location.state;
const [patients, setPatiens] = useState('');
useEffect(() => {
getPatients();
}, [])
const getPatients = () => {
api.getDoctorById(id).then(response => {
setPatiens(response.data)
})
}
console.log(patients.users)
return (
<div>
<div className="container">
<h2 className="text-center">List of Patients</h2>
<table className="table table-bordered table-striped">
<thead>
<th>Employee First Name</th>
<th>Employee Last Name</th>
<th>Number</th>
</thead>
<tbody>
{
patients.users.map(patient =>
<tr>
<td>{patient.firstName}</td>
<td>{patient.secondName}</td>
<td>{patient.number}</td>
</tr>
)
}
</tbody>
</table>
</div>
</div>
) }
for loop, forEach, and with Object.keys don't work as well. How I can loop through it and display the details?

