-
Notifications
You must be signed in to change notification settings - Fork 30
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
formik Allow Value Props for overrides #359
Comments
The use case I come across often is one field depending on another. I like the alternative idea you proposed, but it would be nice if there was a prop available for that. Either one that accepts a function or object and changes depending on another field OR a prop that will change another field's value based on this field. |
Allowing a value prop to be passed down enables a bad pattern IMO. I think we want to encourage managing the state of the form with Perhaps a |
I see 2 patterns here:
I agree that we need to stick to one pattern instead of allowing two patterns because it can cause people's code to be messy in the long run, especially if two developers have different approaches to managing form state when doing maintenance. |
allowing |
Maybe we start a dev blog and link to it like https://kentcdodds.com/blog and include examples on how to implement that sort of logic properly. availity.github.io/dev-blog 🚀 ❓ |
🚀 Feature request
Current Behavior
All
formik
inputs, selects, and dates don't allow value props to be passed in likeavaility-reactstrap-validation
does. Maybe its time we add this in here or we should kill this issue with fire and re-open later if we think our opinion changes.Desired Behavior
When a value is passed in as a prop to
<Input value="hello" />
that value should override the one provided fromformik
and also update the current value if they are not equal.Suggested Solution
Add
effect
logic that takes thevalue
from the props and compares it to theformik
field value and if different, updates the field value for that input.Who does this impact? Who is this for?
All users wanting to manage field state in HOCs etc.
Describe alternatives you've considered
As an alternative, if one field is dependent on the output of another, you can use the
setFieldValue
fromuseFormikContext
in order to achieve this.Additional context
We shouldn't have to worry about putting extra renders on the component. At most it will be 1 more extra render as we are updating the field value of the component once and then it should re-render without calling the validation logic.
The text was updated successfully, but these errors were encountered: