I have a functional component which is reading data from an API. I have defined an Interface but unable to assign API data to Interface, followed by loop and display in table using Map in react.
Interface
export interface IEziTrackerStatus{
Schedules: EziSchedules [],
eziClient: {
clientId: number,
isActive: boolean,
name: string
}
}
..
export interface EziSchedules
{
id: number,
startTime: Date,
endTime: Date
}
component
const MyComponent = () => {
const [eziStatusCollection, setEziTrackerStatus] = useState<IEziTrackerStatus>();
useEffect(() =>{
getEziTrackerStatusReport();
},[]);
const getEziTrackerStatusReport = () =>{
(async () =>{
try{
const resp = await apiRequest(EcpApiMethod.GET, `${api.eziTrackerStatus}`, null);
setEziTrackerStatus(resp);
var x= eziStatusCollection; //HELP HERE - Undefined error
debugger;
}
catch (error) {
console.log(error);
}
})();
}
need help here
{eziStatusCollection && eziStatusCollection.eziAreaManager ????
<table className="table">
<tr>
<td>SideIt</td>
</tr>
{
eziStatusCollection.Schedules.map(item => (
<tr>
<td>{item.siteId}</td>
</tr>
))
}