I have a flatlist where it gets the itemCount from another page, I increment it with a button, its value changes but won’t be seen on the screen without pressing ctrl-s or going to another page and return.
<FlatList
extraData={store}
data={store}
renderItem={({ item }) => {
return (
<View style={styles.itemCountView}>
<TouchableOpacity style={styles.up}
onPress={() => item.itemCount++}>
<MaterialIcons name="arrow-drop-up" size={36} color="#ddd"/>
</TouchableOpacity>
<Text style={styles.itemCountText}>{item.itemCount}</Text>
</View>
)
}}/>
am I missing something? Maybe using the extraData
the wrong way?
any type of help is appreciated
3
Answers
to re-render the flat list you have to pass the variable in extraData which is changing its value.
extraData prop – It re renders the flat list when the given variable changes its value.
You can also manage with state variable like eg below : –
You can map it like below
Just add
keyExtractor
to your FlatlistkeyExtractor={(item, index) => index.toString()}
and it should look like this