I am trying to populate key value for picker element in react native from a kay, value pair. The app crashes when i try to pass the key-value list.
for example:(This does not work)
-- In the constructor
stateList: [{1:'Fortsworth'},{2:'Chicago'}],
--In the render()
this.state.stateList.map( (s, i) => {
console.log('key='+i+',value='+s);
return <Picker.Item key={i} value={s} label={s} />
});
However it only works if i pass array without key value pair. the below code works.
-- In the constructor
stateList: ['Fortsworth','Chicago'],
--In the render()
this.state.stateList.map( (s, i) => {
console.log('key='+i+',value='+s);
return <Picker.Item key={i} value={s} label={s} />
});
I need to pass the key as "1" and value as "Fortsworth" to the picker. Appreciate your inputs.