Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

selectedItem() giving previous value in onChangeText handler #104

Open
JeremyBradshaw7 opened this issue May 11, 2018 · 1 comment
Open

Comments

@JeremyBradshaw7
Copy link

JeremyBradshaw7 commented May 11, 2018

When I evaluate selectedItem() or selectedIndex() as part of the onChangeText callback, it is returning the previous value, not the new value. I have an id and a value in my data items so just the text value is not enough. The only way I can get the new id is to put a timeout in, 1000ms is enough but 100ms isn't, so I imagine it's waiting for animation to finish (even if I put an animationDuration of 0 in, it's still animating the ripple slowly)

        <Dropdown
          labelFontSize={0}
          ref='picker'
          data={data}
          value={this.state.value}
          onChangeText={(value) => {
            console.log(value); // gives new value OK
            setTimeout(() => {
              let me = this.refs['picker'];
              console.log('selected item', me.selectedItem(), me.selectedIndex()); // gives previous item & index
            }, 100);
          }}
          animationDuration={0}
        />

I don't want to have to search in my data by value just to get the id, and I need the new id immediately upon selection. Is there a workaround or fix?

@JeremyBradshaw7 JeremyBradshaw7 changed the title selectedItem() giving old value selectedItem() giving previous value in onChangeText handler May 11, 2018
@ryachza
Copy link

ryachza commented May 14, 2018

Looking at the source, it seems like the callback should receive the index as the second parameter:

if ('function' === typeof onChangeText) {
  onChangeText(value, index, data);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants