On Android, onValueChange is triggered on render when an item has a value of empty string
See original GitHub issueDescribe the bug
onValueChange
triggers immediately upon render, without having made any change.
This only occurs on Android, with react-native-picker-select v5.2.3 and above
To Reproduce
In the items
array passed to RNPickerSelect
, if one of the items has a value of empty string, then onValueChange
will trigger immediately upon render.
items array example for triggering the issue:
[
{ label: 'item', value: '3' },
{ label: 'item 2', value: '' },
]
Expected behavior
onValueChange
should only trigger when a value changes.
Smartphone:
- OS: Android 5.1
- react-native-picker-select version: 5.2.4
- react-native version: 0.55.4
- react version: 16.3.1
Reproduction and/or code sample
https://snack.expo.io/SyFyj2DN4
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Android Picker Not Consistently Firing onValueChange #15556
value = null it does not trigger onValueChange for first item. So how we can define Picker without any pre-selected value?
Read more >React controlled component input value with empty string
From the docs: "User input will have no effect on the rendered element because React has declared the value" . To solve this...
Read more >Unit Testing in React: Full Guide on Jest and Enzyme Testing
Check the onChange event, for that mock onChange callback => render date input component => then simulate change event with new target value...
Read more >react-native-element-dropdown - npm
Selected value. A array containing the "valueField". placeholder, String, No, The string that will be rendered before dropdown has been selected.
Read more >Side-effects in Compose - Android Developers
These actions should be called from a controlled environment that is aware of the lifecycle of the composable. In this page, you'll learn...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
How bizarre - looks like the culprit was
left: 0
when using the headless mode – which isn’t needed anyways.Verify that #144 fixes it for you and i’ll merge it in.
There are some upstream picker issues on Android that have been fixed recently - this one may be related.
Update! I was finally able to create a snack that reproduces this issue. As it turns out, it did not have to do with an empty array, but instead with a value of empty string, as I’ve now explained above. I’ve also figured out that it was a change in 5.2.3 that caused this issue to occur. I hope this helps!