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

update values upon re-entering modal

$
0
0

In my component ContactList, I map a few items like this:

  return (<View style={styles.users}>      {data.users.nodes[0].userRelations.map(        (item: { relatedUser: RelatedUser; id: number }) => {          const userName = item.relatedUser.firstName          const numberOfFriends = item.relatedUser.userRelations.length;          return (<View style={styles.item} key={item.id}><TouchableOpacity onPress={() => setIsUserVisible(true)}><Thumbnail                  source={{                    uri:'https://cdn4.iconfinder.com/data/icons/avatars-xmas-giveaway/128/afro_woman_female_person-512.png',                  }}></Thumbnail></TouchableOpacity><View style={styles.nameNumber}><Text style={styles.userName}>{userName}</Text></View><UserDetails                firstName={item.relatedUser.firstName}                rating={item.relatedUser.rating}                numberOfFriends={numberOfFriends}                onDeleteContact={onDeleteContact}                isUserVisible={isUserVisible}                setIsUserVisible={setIsUserVisible}></UserDetails></View>          );        },      )}</View>  );};

They appear somewhat like this.

enter image description here

Now I want that when I click on each the thumbnail of each item, a new modal should appear along with the details of that particular user. However, what happens is that when I exit my modal and click on some other user's thumbnail, I still get info about the user I previously clicked on. From my modal, I am calling another component.

This is how my modal component looks like:

export const UserDetails: React.FunctionComponent<UserProps> = ({  firstName,  rating,  numberOfFriends,  onDeleteContact,  isUserVisible,  setIsUserVisible,}) => {  console.log(isUserVisible);  return (<Modal visible={isUserVisible}><View style={styles.container}>        {/* <View> */}<View><TouchableOpacity            style={styles.cross}            onPress={() => setIsUserVisible(false)}><Thumbnail              source={{                uri:'https://cdn0.iconfinder.com/data/icons/very-basic-android-l-lollipop-icon-pack/24/close-512.png',              }}></Thumbnail></TouchableOpacity>          {/* <Text>HELLOO</Text> */}</View><View style={styles.searchLocationContainer}><UserInfoContainer            firstName={firstName}            rating={rating}            numberOfFriends={numberOfFriends}></UserInfoContainer></View></View></Modal>  );};

enter image description here

The first name, rating etc don't update. How can I fix this?


Viewing all articles
Browse latest Browse all 6213

Trending Articles



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