React-native: Android Picker onValueChange is Firing on Initialization

Created on 22 Feb 2017  路  5Comments  路  Source: facebook/react-native

Description

I have a Picker whose list loads dynamically, based on what has previously been selected (mutually exclusive options). When I select a value from the list, I would like to move it to a different list and remove it from the Picker options. The issue is that, it selects the topmost value and fires the onValueChange for that value every time the list is re-rendered due to the setState. This causes every value to fire an event and empties the list.

Reproduction

RN Play Sample Here

Solution

onValueChange should not be fired when the Picker is initialized on Android. It should only trigger when an option is manually selected by the user.

Additional Information

  • React Native version: 0.41.2
  • Platform: Android
  • Operating System: Mac OS Sierra 10.12.3
Locked

Most helpful comment

All 5 comments

:+1:

Does anyone have a workaround for this? Being able to change state on onValueChange is pretty crucial.

@wrell Currently my workaround is that I moved the onValueChange code to a button that fires it onPress and save the selected value to state. This prevents any bunk submissions. Obviously, this may not be a workable solution for everyone, but it's better than nothing.

I have the same issue, the workaround mentioned in #9220 does not work for me.

Did anyone find any other solution to prevent onValueChange from firing?

Hi there! This issue is being closed because it has been inactive for a while. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. Either way, we're automatically closing issues after a period of inactivity. Please do not take it personally!

If you think this issue should definitely remain open, please let us know. The following information is helpful when it comes to determining if the issue should be re-opened:

  • Does the issue still reproduce on the latest release candidate? Post a comment with the version you tested.
  • If so, is there any information missing from the bug report? Post a comment with all the information required by the issue template.
  • Is there a pull request that addresses this issue? Post a comment with the PR number so we can follow up.

If you would like to work on a patch to fix the issue, contributions are very welcome! Read through the contribution guide, and feel free to hop into #react-native if you need help planning your contribution.

Was this page helpful?
0 / 5 - 0 ratings