I'm new to React Native and am creating a screen with several Switches, the number and specifics of which aren't known until runtime.
In the onValueChange
callback, the new value of the Switch is passed in, but how can I identify which Switch was actually pressed? (code simplified)
export default class Class1 extends Component
{
switchhit(newval)
{
console.log('*How do I know which switch was hit?* newval=' + newval);
}
render()
{
let ii, arrC = [];
for (ii = 0; ii < sSettChcs.length; ii++)
{
let jsx0 =
<View>
<View>
<Text>{ sSettChcs[ii] }</Text>
<Text>{ sSettDesc[ii] }</Text>
</View>
<View>
<Switch
onValueChange = { (newval) => this.switchhit(newval) }
value = { true } />
</View>
</View>;
arrC.push(jsx0);
}
let jsx =
<ScrollView>{ arrC }</ScrollView>;
return jsx;
}
}
Note that this is a simplified example and the final screen will have Components of type TextInput
, Picker
, etc. so my question isn't really specific to just Switch
.