Open jkahlina opened 2 years ago
I have exactly the same issue
This is still an issue. Complex validation functions that might not be dependent directly on form value/values but on additional data, would still throw that warning when following the documentation and changing the key of the field. In a state of React where we can simply memoize the validate function, we don't even need final form to do that for us.
I think I found a workaround. If I use the prop data
instead of key
then the dynamic validation works and there are no warnings/errors.
See fix: https://codesandbox.io/s/final-form-console-error-forked-7cesti?file=/src/App.tsx
Also, now it is not working for final-form-arrays. I am planning to open PR with forwarding prop data
in useField
:
https://github.com/final-form/react-final-form-arrays/blob/master/src/useFieldArray.js#L62-L69
I'm not sure if this is the correct fix. Maybe I'm missing some cases.
Are you submitting a bug report or a feature request?
Bug report
What is the current behavior?
Changing the key of a field in order to rerender it with a new
validate
prop results in a console warning.Example console warning from provided sandbox:
What is the expected behavior?
There is no warning on rerender of field.
My understanding is that this is the proper way to change the inline validation on a field:
Sandbox Link
Example with a conditional validate function
What's your environment?
Other information
There are a few related issues that have a similar symptom: