Skip to content

async onValueChange called twice  #311

@AregShahbazian

Description

@AregShahbazian

Possibly duplicate of this issue.

Describe the bug

When onValueChange awaits an async call, the delay causes it to be fired twice. Once from the manual select, and once from getDerivedStateFromProps

To Reproduce

Steps to reproduce the behavior:

  1. Create a RNPickerSelect
  2. set onValueChange to be an async function that awaits something that takes 1000 ms
  3. Try to change the value
  4. Value will not change, or it will flicker back and forth

Expected behavior

Only 1 call of onValueChange

Screenshots

n/a

Additional details

  • Device: android
  • OS: Ubuntu
  • react-native-picker-select version: 7.0.0
  • react-native version: 0.62.2
  • react version: 16.11.0

Reproduction and/or code sample

Example repo here

Suggestion for fix

Awaiting the call here seems to fix the problem. Not sure if this breaks anything else though.

    async onValueChange(value, index) {
        const { onValueChange } = this.props;

        await onValueChange(value, index);

        this.setState((prevState) => {
            return {
                selectedItem: prevState.items[index],
            };
        });
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions