I'm struggling to properly use .map() on a state object's array to display elements. Here's my code
class EventListFront extends Component {
state = {
currentEvent: new event(),
events: new eventList(),
}
...
<View>
{this.state.events.events.map(event => {
<View key={event.id}>{event.title}</View>})}
</View>
My Event structure is as follows:
class event {
constructor(
id = -1,
name = 'UNSET',
description = 'UNSET',
location = 'UNSET',
...
) {}
(eventList is an array of events, and it redundantly has an identifier 'events')
With this implementation, i have nothing showing when I add to the array. I've tried using a FlatList, but that requires keys/IDs for each element. I'm not sure how to
- update the page with the new list when a new event is added
- get the elements of events to be displayed in elements using .map()
- use the generated ID so that it may properly render with a FlatList instead.