-
-
Notifications
You must be signed in to change notification settings - Fork 482
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
Why do we have to clone mutators? #704
Comments
Additional comment: If I remove the spread operator: <Form
onSubmit={onSubmit}
mutators={arrayMutators}
render={({ Then the TypeScript compilation fails with
export interface DefaultType {
insert: Mutator
concat: Mutator
move: Mutator
pop: Mutator
push: Mutator
removeBatch: Mutator
remove: Mutator
shift: Mutator
swap: Mutator
update: Mutator
unshift: Mutator
} while final-form expects mutators of the type I don't understand why TypeScript fails on this one. But if it's the reason why we have to use the spread operator, I think it'd be better to improve the types rather than force people who use JS to write an ugly syntax. I fixed the TypeScript error with an even uglier mutators={(arrayMutators as unknown) as { [key: string]: Mutator<object> }} |
Y think |
I was wondering the same thing last night looking at <Form
onSubmit={onSubmit}
mutators={{
pop: arrayMutators.pop,
insert: arrayMutators.insert,
setFieldData
}}
render={({ |
What is the current behavior?
The documentation shows that external form mutators should be cloned before passing them to a Form component:
In the case of
final-form-arrays
,arrayMutators
is a set of functions. Cloning this set has absolutely no effect. I checked that, if I remove the clone, it still works fine in the FieldArrays example.Since the clone is useless in that case and it works without it, my question is: Why does the documentation emphasize the need for a clone?
Sandbox Link
https://codesandbox.io/s/kx8qv67nk5
Thanks for a great lib.
The text was updated successfully, but these errors were encountered: