-
Notifications
You must be signed in to change notification settings - Fork 24k
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
Manually bind PickerAndroid instance methods #9789
Conversation
Instead of using es7 class property syntax, manually bind the methods in the component's constructor. The class property syntax is still experimental and seems to fail randomly where `this` ends up bound to `undefined`.
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at cla@fb.com. Thanks! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
@dzautner updated the pull request - view changes |
@dzautner updated the pull request - view changes |
We're using this syntax a lot and it should be reliable thanks to Babel. It looks like the code is equivalent actually. Can you consistently reproduce the bug with |
@mkonicek, sorry for not providing enough information. Yes, we can consistently reproduce the issue with this specific component. We actually use this exact code to resolve the issue temporarily until it is resolved upstream. |
@dzautner updated the pull request - view changes |
@dzautner updated the pull request - view changes |
Can you please determine why the current code is breaking? |
I'll try to run some tests and narrow it down to the exact cause of the issue. |
I narrowed the issue down to an issue with babel the is already acknowledged. When using babel with passPerPreset the class property syntax will not be bound to the wrong context. |
Yeah, that's unfortunate. If you have transform-class-properties in the plugins section then it will work. |
👍 thanks! |
In the current version of react-native, the Picker component would some times fail on Android due undefined context (
this === undefined
) in the methods that are defined using the experimental class property syntax.As this is experimental syntax which seems to be unreliable in its current form and usage, I suggest to manually bind these methods in the component's constructor.