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

Hide picked items in a FlatList

$
0
0

I'm using react-native FlatList to render out a punch on elements the data of which comes from an external API.

I want to prevent the user from picking the same item twice. So the way I'm going about this it hiding the item after they pick it.

If, let's say, I have a state picked like so

  const [ picked, setPicked ] = useState(false);

changing it will of course hide all the elements.

<FlatList        {/*some other props*/}        data={allCards}        renderItem={(card: ListRenderItemInfo<CardsProps>) => (<TouchableOpacity            style={[ styles.holder, { display: picked ? "none" : "flex" } ]}            onPress={() => handleChoice(parseInt(card.item.id))}><Card             {/*some card props*/}            /></TouchableOpacity>        )}      />

How can I go about changing the state for only one element inside the FlatList??Is there a better approach you would recommend to do the same job?


Viewing all articles
Browse latest Browse all 6287

Trending Articles



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