Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6213

If else within a map

$
0
0

Each of the user relations object looks like this:

"userRelations": [    {"relatedUser": {"id": 4,"firstName": "Jack","lastName": "Miller"      },"type": "FRIEND"    },    {"relatedUser": {"id": 3,"firstName": "Rhena","lastName": "Tahoma"      },"type": "CONTACT"    }  ]

Currently, my code renders all relatedUsers. However, I only want to render those which have "type": "contact". Is it possible to check for this condition within the return

type RelatedUser = {    firstName: string,    lastName: string,    id: string,    phoneNumber: string,  };  type RelationType = {    type: string,  };export const ContactList: React.FunctionComponent<UserProps> = ({ data }) => {  if (!data) return null;  return (<View style={styles.users}>    {data.users.nodes[0].userRelations.map(      (item: { relatedUser: RelatedUser, type: RelationType}) => {        const userName = item.relatedUser.firstName.concat('').concat(item.relatedUser.lastName);        // if (item.type: "CONTACT"){        return (<View style={styles.item} key={item.relatedUser.id}><Text style={styles.userName}>{userName}</Text></View>        );      },    )}</View>  );};

Viewing all articles
Browse latest Browse all 6213

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>