onValueChange is called multiple times
See original GitHub issueDescribe the bug
Method onValueChange is called multiple times when I dynamically change items of select
To Reproduce
Steps to reproduce the behavior:
const items_1 = [ { label: 'one', value: 1, key: 'one', }, { label: 'two', value: 2, key: 'two', }, ];
const items_2 = [ { label: 'three', value: 3, key: 'three', }, { label: 'four', value: 4, key: 'four', }, ];
const [itemValues, setItemValues] = useState(false);
<View
style={{
borderStyle: 'solid',
borderWidth: 1,
borderColor: 'black',
margin: 10,
padding: 10,
}}>
<RNPickerSelect
items={itemValues ? items_1 : items_2}
placeholder={{
label: 'Select value',
value: '',
key: 'select value',
}}
onValueChange={value => console.log('value: ', value)}
/>
</View>
<Button
title="change items"
onPress={() => setItemValues(!itemValues)}
/>
look at logs and change items
Expected behavior
onValueChange should be called only when user interact with picker.
Additional details
- Device: iOS simulator iPhone 12 (and all physical devices, I tested 3 iPhones)
- OS: iOS 14.4
"dependencies": { "react-native-picker-select": "^8.0.0", "react": "17.0.1", "react-native": "0.64.0" },
Last version when it is working correctly is 8.0.2
Issue Analytics
- State:
- Created 2 years ago
- Reactions:5
- Comments:6
Top GitHub Comments
For me, it is also fired when I press the “Done” button in iOS picker. And that returns a null value which replaces the actual selected value
Duplicate of https://github.com/lawnstarter/react-native-picker-select/issues/112 ?