availity-react
availity-react copied to clipboard
formik Allow Value Props for overrides
🚀 Feature request
Current Behavior
All formik
inputs, selects, and dates don't allow value props to be passed in like availity-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 from formik
and also update the current value if they are not equal.
Suggested Solution
Add effect
logic that takes the value
from the props and compares it to the formik
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
from useFormikContext
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.