For readability, you should do those loops before the return statement.
In addition, you need to add a key property to your <ReportAlarmRow> component.
A "key" is a special string attribute you need to include when creating lists of elements.
Keys help React identify which items have changed, are added, or are removed. Keys should be given to the elements inside the array to give the elements a stable identity.
Lists and Keys - React documentation
I set a key with key={alarm[i].id} but I don't know what attributes are in your alarm object.
Please, use a unique int value !
Keys Must Only Be Unique Among Siblings
Try like this
constructor(props) {
super(props);
// State
this.state = {
listOfAlarms: []
}
}
render() {
const reports = this.state.listOfAlarms.map((alarms) => {
if (alarms.report) {
return alarms.report.map((alarm) =>
<ReportAlarmRow alarm={alarms} alarmType={alarm} key={alarm.id} />
);
}
});
return {
<div>
{ reports.length ? reports : null }
</div>
}
}
=>