picker
picker copied to clipboard
OnValueChange is automatically called many times when navigate to other screen
Summary
Let's say there are two screens in a stack navigator ,A and B.
There are a Picker and a Button on Screen A , you can press the Button to navigate to Screen B.
The issue is, you press the Button, Screen B shows up, but when you check the log, you will find the Picker's onValueChange function is called 3 times with a same value, how could Picker's value be changed 3 times when user navigates to other screen?
Reproduce Code
https://snack.expo.dev/@yaohj/picker-onvaluechange-issue
Run it on iOS, press the button 'Go' and check the log.
Environment
react-native": "0.64.0
@react-native-picker/picker": "^1.16.6
@react-navigation/native": "^6.0.2
@react-navigation/stack": "^6.0.7
If you see this, I think you have the same problem. I still don't know why and how to solve it. but I find a way to reduce the re-renders, in onValueChange,compare the old and new value, and update state only when they are different.
Hope developers could pay attention to this issue someday.