I have a class component, where I am getting data from async request in its local props. This data is in form of array, which I loop through and display some list elements. For the first time component renders, I receive empty array and then populated array from server. Next time component renders, I receive empty array again, Which means data in local props is null now, which makes sense. Any explanations how to deal with that, so I have populated array.
See code below:
const {List} = this.props; //data in local props of a component
<ListGroup>
{
List.map((f, index) => {
return (
<ListGroup.Item
action
href=""
key={f.get('ID')}
value = {f.get('ID')}
onClick={this.handleClick}
>
{f.get('NAME')}
</ListGroup.Item>
)
})
}
</ListGroup>
Then I have some button to switch back forth between two components. When I want to swtich to this list the local data in props is undefined or I get error says "TypeError: Cannot read property 'map' of undefined". Hope it is enough, not sure how I can show complete code here.