I have some buttons in my flatlist like below
const renderItem = ({ item }) => <Item name={item.name} slug={item.slug} />;
const Item = ({ name, slug }) => {
return (
<TouchableOpacity
delayPressIn={0}
onPress={() => {
dispatch(setLanguage(slug));
}}
>
<View
style={[
styles.item,
{ backgroundColor: languages == slug ? "#940062" : "black" },
]}
>
<Text style={styles.title}>{name}</Text>
</View>
</TouchableOpacity>
);
};
return (
<SafeAreaView style={styles.container}>
<FlatList
horizontal={true}
data={jsonLang}
renderItem={renderItem}
keyExtractor={(item) => item.id.toString()}
/>
</SafeAreaView>
);
};
The above code works fine, when I click it is changing the background? But background color change is delayed by 1 second. Is this the right approach to change the background color of the button?
Thank you.
P.S: the setlanguage is my reducer in my redux
setLanguage: (state, action) => {
state.language = action.payload;
},