const _DATA = [{
code: 'code1',
name: 'Jagger'
},{
code: 'code2',
name: 'Tigger'
},{
code: 'code3',
name: 'Lion'
}]
<SelectPicker
data={_DATA.map(x => {return {label: x.name, value: x.code} })}
style={{ width: 224 }}
defaultValue={_DATA[1].label}
/>
How do I set the value of code1
for example I have a form then it will set the code1
when opening the form/drawer. cause I have a list then I have edit button. when I try to select the data which is the code1
then it should automatically display. but on my side it didn't work.
You don't have to map data. SelectPicker support pass valueKey and labelKey. And you can pass code value to SelectPicker.
const _DATA = [{
code: 'code1',
name: 'Jagger'
},{
code: 'code2',
name: 'Tigger'
},{
code: 'code3',
name: 'Lion'
}]
<SelectPicker
data={_DATA}
valueKey="code"
labelKey="name"
style={{ width: 224 }}
defaultValue={_DATA[0].code}
/>