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

change state for a specific children in a loop with "useState"

$
0
0

I am using React native andI have a loop in which some property types are being displayed,

i created only one state for it because property types are being fetched from DB.What i want to do is to show them selected. kindly show me a way to achieve it.

     const [propBCol, setPropBCol] = useState('#EDEDEE');     const [propTCol, setPropTCol] = useState('#000000');  {propType.map((item, index) => {                    return (                      <TouchableOpacity style={{          backgroundColor: propBCol,          ...ListingFilterStyles.filterAnyBtn,          ...ListingFilterStyles.btnMale,          }}          onPress={() => proptypes(item)}><Text style={{color: propTCol}}>{item.value}</Text></TouchableOpacity>    );  })}

the propTypes function:

const proptypes = item => {   setPropBCol('red');   setPropTCol('White')}

enter code here

How can i change the selected item color, by above code all are item colors are being changed


Viewing all articles
Browse latest Browse all 6287

Trending Articles



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