question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

On Android, onValueChange is triggered on render when an item has a value of empty string

See original GitHub issue

Describe 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:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
lfkwtzcommented, Feb 6, 2019

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.

0reactions
zaytricommented, Feb 6, 2019

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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found