API data is fetched when component mounts, and state is set in the form
sectionData: {
course: null,
section_id: null,
semester: null,
number: null,
seats: null,
meetings: [],
open_seats: null,
waitlist: null,
instructors: []
},
For reference the relevant API data looks like this
"meetings": [
{
"days": "TuTh",
"room": "0324",
"building": "IRB",
"classtype": "",
"start_time": "11:00am",
"end_time": "12:15pm"
},
{
"days": "MW",
"room": "3120",
"building": "CSI",
"classtype": "Discussion",
"start_time": "9:00am",
"end_time": "9:50am"
}
],
Using keys like course and section_id is fine, since they are predefined with null. However, if I am to map over each meeting object in meetings, and say access "days" or "room", each meeting is obviously undefined.
{this.state.sectionData.meetings.map(meeting => this.renderMeetings())}
renderMeetings(meeting) {
return (<div key={meeting}>
{meeting.days}
</div>)
}
Any easy fixes without having to make an entirely new Meeting component to predefine said keys? Merely checking for an undefined prevents React from crashing, but doesn't help with actually displaying the data.