-
Notifications
You must be signed in to change notification settings - Fork 503
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
(FIX) onValueChange being called twice #369
Comments
This issue is present on Android in the new version of the package. It works fine on iOS. |
This is still an issue. Here is a link showing the problem: https://snack.expo.io/L0LhveQem A possible solution could be transforming the onValueChange(value, index) {
const { onValueChange } = this.props;
this.setState((prevState) => {
return { selectedItem: prevState.items[index] }
}, () => onValueChange(value, index));
} In addition, I cannot understand what this line of code is for: react-native-picker-select/src/index.js Line 161 in ca6488c
I think everything will work fine even without this line. Am I wrong? If you are ok with these observation I can provide a small PR to fix. |
hello @federicobadini! I've only commented this line and it's not being called twice anymore but only on iOS react-native-picker-select/src/index.js Line 161 in ca6488c
I don't understand what that line is for either updateSorry, was my mistake on Android, now it is not being called twice in both platforms by commenting that line |
Why is this line still a part of the code? |
Issue still persist |
Still have the issue |
1 similar comment
Still have the issue |
Issue still exists |
Hello! 🙂
As some other users have noted, it seems that there is often an issue with this library where the "onValueChange" function is called twice. (For example, see issues #311 , #265 , #242 , #180 , #112 ).
In my case, I had this issue while using the component with reduxForm, which made the component either: 1) bounce back to the previous value every time I tried to select something on iOS, or 2) simply not change anything when selecting a value on Android. (Probably the same thing was happening under the hood, the Android picker just wasn't animated).
I have solved the issue in my local app by replacing getDerivedStateFromProps with compononentDidUpdate in the index.js file of the react-native-picker-select component. I have opened a pull request ( #368 ) with the hope that it may solve others' problems as well.
Describe the bug
The picker doesn't work because the onValueChange call back is called twice, making the selected value reset itself each time. (See GIF).
To Reproduce
Create a custom Field component with the Redux Form library (such as the one I added below). Try to select a value on iOS or Android.
Expected behavior
New value is selected with no problems.
Actual behavior
Value is selected, but the onValueChange callback is immediately called again, forcing the value to go back to its previous state.
Screenshots
Additional details
Reproduction and/or code sample
The text was updated successfully, but these errors were encountered: