Reputation: 239
I am setting up a client code and the error "Cannot read property '' of undefined" keeps occur.
TypeError: Cannot read property ' ' of undefined
It is interesting that if I refresh the page several times then suddenly it works! For example, the home page is random within 10 times, menu page shows me an error page at the first time, half loaded at first refresh, fully loaded at second refresh.
I think props can't get data correctly right away. So I think I can solve this problem by refreshing automatically until props get correct data.
Is there any way refreshing until I get the props?
Or any other solution about this problem?
menu error
home error
Upvotes: 0
Views: 2452
Reputation: 42
Yea, you will need to confirm that the data object exists before doing a conditional. so
loading || {data || !data.me || !data.getPlaces}
Upvotes: 0
Reputation: 1833
First you need check exist of data
, and then fields in this object:
loading || (data && (!data.me || !data.getPlaces)) ? ...
Upvotes: 1
Reputation: 969
Try to change your if condition to:
{loading || !data || !data.me ...
Upvotes: 0