react-final-form-arrays
react-final-form-arrays copied to clipboard
Can't use custom mutators with FieldArray
Are you submitting a bug report or a feature request?
Potential bug report though it might be by design
What is the current behavior?
If I create a custom mutator and then try to use it in a field array component by calling fields.customMutator then the values in the array passed into the custom mutator are overridden.
What is the expected behavior?
I would expect that the parameters I pass into the function would not be overridden
Sandbox Link
https://codesandbox.io/s/react-final-form-field-arrays-38gj3
What's your environment?
"react-final-form": "6.3.0",
"react-final-form-arrays": "3.1.0",
Other information
The mutator works fine when it is passed in directly but if that is how they're supposed to be used then why do they show up as properties of the fields parameter?
you need to change your mutator to something like this:
clearValue: (args, state, { changeValue }) => {
console.log(args[1]);
changeValue(state, args[1], () => undefined);
},
you had this for your mutator declaration:
clearValue: ([name], state, { changeValue }) => {
which was returning customers for the name prop, but you wanted customers.firstName which was the second argument
That's fine and makes it work for the specific scenario but if I want to use the mutator on normal fields too then the name is in args[0] and args[1] is undefined which means if I want a generic solution I'm looking at name = args[args.length -1]?