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
Allow setValues to extend rather than replace #887
Comments
Simple change suggestion in
If the maintainers wish for this change to happen I can provide PR and test |
Hola! So here's the deal, between open source and my day job and life and what not, I have a lot to manage, so I use a GitHub bot to automate a few things here and there. This particular GitHub bot is going to mark this as stale because it has not had recent activity for a while. It will be closed if no further activity occurs in a few days. Do not take this personally--seriously--this is a completely automated action. If this is a mistake, just make a comment, DM me, send a carrier pidgeon, or a smoke signal. |
ProBot automatically closed this due to inactivity. Holler if this is a mistake, and we'll re-open it. |
Open up! Make it work like setState, please |
+1 for this feature. |
any updates on this? I could try to implement this, making it work like |
Current Behavior
Currently
setValues
will replace all current form stateDesired Behavior
A flag to change that behaviour to simply extend current values would be nice
Suggested Solution
I propose
setValues
signature is changed tosetValues: (fields: { [field: string]: any }, replace?: bool = true) => void
. Passing false would extend current values rather than replace it (alavalues ={...currentValues, ...newValues}
Who does this impact? Who is this for?
The scenario I have experienced is sometimes I want a subform to override the values of the parent form. Therefore, I pass down
setValues
to the child that might override the values. However, I do not wish for the child to be unnecessarily aware of all parent values, so passing downvalues
to do something likesetValues({ ...values, [key]: newValue })
seems a bit much. In that case I could dosetValues({ [key]: newValue }, false)
instead. That way I do not have to worry about passing down the entire form's values nor extendingsetValues
behaviour.Describe alternatives you've considered
Right now I am passing down
setValues={(childValues) => setValues({ ...values, ...childValues })
to the child instead of just passingsetValues
. It works fine, but it gets a bit cumbersome because I have to extendsetValues
this way everywhere where I need this behaviour.Additional context
Other issue: #356
The text was updated successfully, but these errors were encountered: