Listing Emails error using React


#1

What is the proper way of listing users email in React.
here’s my code but it gives me an error

{ usersList.map((item, i) =>
    <tr key={i}>
        <td>
            { item.emails[0].address }
        </td>
        <td className="negative">
            <button className="ui mini green basic button"   >
                { item.access }
            </button>
        </td>
        <td >
            <Time value={ item.createdAt } format="YYYY/MM/DD h:mm A"  />
        </td>

    </tr>
)}

error shows TypeError: Cannot read property '0' of undefined


#2

anyone have experienced with this error?


#3

The error says that ‘emails’ for ‘item’ is undefined, so it can’t access to the index 0 (of ‘emails’ for that ‘item’) because there aren’t any.
Now, it can be that just some item don’t have emails or it seems ‘emails’ is not defined at all in the whole collection or whatever it is.

Can you explain better what those item are (the whole collection structure interesting emails)?


#4

thanks @meteorf4n…I have two subscriptions from Meteor.users. One doesn’t have the the email and the other have…but it seems it is overwriting the other I am sure. =(

anyway, i just change my two subscription into one to address the problem. It’s working now.