Ive tried several forum solutions but still stumped. Thanks for any help...
I am trying to display the number of total posts made by user by taking the most recent post's postCount.
My problem is when user hasn't posted anything yet and this.props.user.myFeed[0].postCount, the redux prop that holds user's posts/feed, hasn't been created yet. The screen tries to load and I get "TypeError: undefined is not an object (evaluating 'this.props.user.myFeed[0]')"
Ive tried several solutions but is there a reason why the simple code below doesn't work.
<Text>Posts: {(this.props.user.myFeed[0]) ? this.props.user.myFeed[0].postCount : 0 }</Text>
Also have tried below:
<Text>Posts: {(this.props.user.myFeed[0] === undefined) ? this.props.user.myFeed[0].postCount : 0 }</Text>
If the store is undefined, shouldn't it simply be 0 ?
Thanks again! -Matt
myFeedis created as an empty array [] when the user is first created. In response to you, I thought thats what I was doing with the code above, checking to see if there is a most recent postmyFeed[0]and then if it is undefined return0; but if it is there, return itspostCountprop. Didn't I write it correctly to perform that check and see if its undefined? Thanks again