Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Form - Migrate setNativeProps to state. #11039
Form - Migrate setNativeProps to state. #11039
Changes from 3 commits
1e1765a
58505b4
50373ab
a7f4f88
3fb74b2
d3e630b
68c1389
c5ce2d3
c8f4299
55bcc8f
951be8f
44b8a95
2cf3288
92dc75d
f505376
f19213c
addf6fc
c7bef85
3b01ab9
150f736
28f5db3
426e24f
b1a6d98
d8e66e8
41d0ebd
24bd378
ff83af2
ddc4050
1273efc
aab173b
c72e7ac
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question from @parasharrajat - How is this change related to removing
setNativeProps
?Rushat:
Anytime a Form input's value is changed,
onInputChange()
is called.If you'll look at Form.js
App/src/components/Form.js
Lines 161 to 166 in 97ebb65
It keeps track of input values based on the key provided to it.
And this "key" is supposed to be the formID used by the Form input.
So our expected function call looks something like this -
onInputChange('Portugal', 'countryPicker')
Prerequisite: Picker is used in a Form.
Now
RNPickerSelect
comes into picture.It passes the picker item's index as the second parameter. (source)
So this is what actually gets called -
onInputChange('Portugal', 156)
. (where 156 is the index of Portugal in a list)Our Form based picker now will try to change the value of an input whose formID is 156.
And bam 💥 our Form based picker doesn't work anymore.
I'm just fixing this by passing the formID as the second param, because we don't care aobut the index lol
This wasn't a problem before because Form previously set the value using ref.setNativeProps.
We're getting rid of that now. So we gotta fix it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The explanation makes sense, but I'm not sure that this is necessary. From the Form docs, the intent of the second param is to:
If you look at Form, we have
const inputKey = key || inputID;
so ifkey
(the 2nd param) is not provided, we will automatically use theinputID
provided to that Picker. The only instance in which we want to pass a 2nd param is if that picker is also controlling the value for a different input. In which case we would provide a custom callback (not yet supported, see this issue) and pass theinputID
of the second input.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rushatgabhane what are your thoughts about my comment above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just started reading this, will get back soon
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, I understand the use of 2nd parameter better now.
I've updated the call to not pass the 2nd parameter.