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

React Native - How to change the style and properties to a pressed row inside a map loop

$
0
0

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.

result


Viewing all articles
Browse latest Browse all 6287

Trending Articles



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