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.

onValueChange is called multiple times

See original GitHub issue

Describe 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:open
  • Created 2 years ago
  • Reactions:5
  • Comments:6

github_iconTop GitHub Comments

2reactions
akshitrcrmcommented, Jun 18, 2021

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

React onChange handler is being called multiple times during ...
The problem is that this function is called about 10 times during page load, which is not intended. I thought it was only...
Read more >
Focus Changes on TextField without any text changes triggers ...
Click on TextField, lose focus and click again or put app in background and reopen, these focus changes calls the onValueChange callback of...
Read more >
OnChange triggers multiple times and actives ... - Reddit
OnChange triggers multiple times and actives OnChange of multiple different fields. I'm trying to edit a form and save it OnChange.
Read more >
Intermittently onChange client script is executed multiple times ...
When there is an onChange client script, intermittently after submitting the form this client script triggered ( twice or sometimes multiple times).
Read more >
Fire OnChange only once - Telerik UI for Blazor
OnChange fires twice. Environment. Product, DropDownList for Blazor, ComboBox for Blazor, AutoComplete for Blazor, TextBox for Blazor, NumericTextBox for Blazor ...
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