You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a large, deeply nested form; the 'root' object is a large configuration object, and the form itself is a mix of various form fields, validations, FieldArrays, etc.
For various fields, I need the value of a different field to determine things like what options should be in a select, or whether a field should be enabled, that kind of thing.
Now, to do so I use two methods interchangeably:
Pass the relevant values down the component chain using regular properties
OR use the values object from useFormikContext(), combined with the getIn() helper to get the specific value
Is one style preferable over the other? I'm mainly thinking of performance, but also explicit dependencies (it's all in Typescript), and I think it might be better to keep things consistent.
Another - less important in this case - factor is that it's all in Typescript, so if I pass explicit objects down the component chain I don't lose typing, whereas with getIn() I have to manually specify what type is expected.
Anyway, I just want to know whether there's one definitely better than the other, or if it's a matter of personal preference.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have a large, deeply nested form; the 'root' object is a large configuration object, and the form itself is a mix of various form fields, validations, FieldArrays, etc.
For various fields, I need the value of a different field to determine things like what options should be in a select, or whether a field should be enabled, that kind of thing.
Now, to do so I use two methods interchangeably:
values
object fromuseFormikContext()
, combined with thegetIn()
helper to get the specific valueIs one style preferable over the other? I'm mainly thinking of performance, but also explicit dependencies (it's all in Typescript), and I think it might be better to keep things consistent.
Another - less important in this case - factor is that it's all in Typescript, so if I pass explicit objects down the component chain I don't lose typing, whereas with
getIn()
I have to manually specify what type is expected.Anyway, I just want to know whether there's one definitely better than the other, or if it's a matter of personal preference.
Beta Was this translation helpful? Give feedback.
All reactions