react-native-picker-select
react-native-picker-select copied to clipboard
itemKey doesn't work
Describe the bug
according to the document: "Will attempt to locate a matching item from the items array by checking each item's key property". but in my testing in IOS, it don't work, but when I change itemKey to value field, it works. (the key and value are same value in my data)
To Reproduce
Steps to reproduce the behavior:
- set itemKey = 1 in code
- in UI, open the picker, then select the second item, press done.
- reopen the picker, found the selected item is still on the second item
Expected behavior
I expect the selected items in the above steps should be the first item(with key=1, also value=1).
when I change the itemKey to value field, it works, everytime reopen the picker, the selected item always be the first.
according to the document, in IOS we should use itemKey, but it seems the value property works and itemKey don't work.
Screenshots
Add screenshots to help explain your problem. If screenshots aren't applicable to this issue, write "n/a".
Additional details
- Device: [e.g. iPhone12]
- OS: iOS17.4
- react-native-picker-select version: ^9.1.3
Reproduction and/or code sample
<RNPickerSelect
onValueChange={(value) => setTimesADayValue(value)}
itemKey={1}
items={ BizType.getTimesADayArray() }
ref={Platform.OS === 'ios' ? pickerRef2 : null}
pickerProps={{ ref: Platform.OS === 'android' ? pickerRef2 : null }}
style={pickerSelectStyles}
useNativeAndroidPickerStyle={false}
onDownArrow={()=>null}
/>
my data items like this:
const timesADayArray = [{label: 'one time a day', value: 1, key: 1}];
for (let j = 2; j <= 12; j++) {
timesADayArray.push({label: j+' times a day', value: j, key: j},);
}
when I change itemKey field to 'value' field, it works.