I would like to change the style when the button is pressed, but just change the pressed one, not all the row list. How can achieve this in React-native. This is what I have tried.
//hooks
const [activeStyle, setActiveStyle] = useState(styles.container);
const handlerOnPress = (item: string, index: number) => {
setActiveStyle({
backgroundColor: AppColors.tertiary,
padding: 10,
borderRadius: 10,
})
}
return data.map( (item, index) => {
return (
<TouchableOpacity
key={ index }
activeOpacity={ 0.3 }
onPress={ () => handlerOnPress( item, index ) }
>
<View style={ activeStyle }>
<Text style={{
...globalStyle.subTitle,
color: AppColors.black
}}>{ item }</Text>
</View>
</TouchableOpacity>
)
} );
I want to achieve something like this, when you press the button, the one that has been pressed change, not all of them.
