I am rendering this list like so
const roomsAttached = this.state.rooms_attached.map((item, index) => (
<View key={index}>
<Text>{index}</Text>
<Switch
thumbColor='#eee'
onValueChange={(value, index) => this.losToggle(value, index)}
value={item.room_attached_los}
/>
</View>
))
I simply cannot access the index from the list item, I have always used a similar syntax and it worked out the box now all I am getting is undefined.
losToggle (los, index) {
console.log('index :', index)
console.log('LOS: ' + los)
}
Can please someone assist? I also tried item
, same issue
Change the passed callback function definition in onValueChange
prop, to this, will works:
onValueChange={value => this.losToggle(value, index)}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.