Are you submitting a bug report or a feature request?
Documentation update request - I'm not sure if that counts as a bug or a feature.
What is the current behavior?
The current documentation for remove and removeBatch methods:
form.mutators.remove
(name: string, index: number) => any
Removes a value from the specified index of the field array. Returns the removed value.
form.mutators.removeBatch
(name: string, indexes: Array<number>) => void
Removes the values at the specified indexes of the field array.
What is the expected behavior?
The documentation above didn't prepare me for the fact that, if there's only one value left in the field array, the result won't be an empty array. If the last element is removed from the array, the whole array gets removed and the field is set to undefined.
Sandbox Link
What's your environment?
Other information
Code that sets the array to undefined if its length is zero: https://github.com/final-form/final-form-arrays/blob/fe3c260939cbdd446a48304dd2df0be2a1c41237/src/remove.js#L20C5-L22C18
Are you submitting a bug report or a feature request?
Documentation update request - I'm not sure if that counts as a bug or a feature.
What is the current behavior?
The current documentation for
removeandremoveBatchmethods:Removes a value from the specified index of the field array. Returns the removed value.
Removes the values at the specified indexes of the field array.
What is the expected behavior?
The documentation above didn't prepare me for the fact that, if there's only one value left in the field array, the result won't be an empty array. If the last element is removed from the array, the whole array gets removed and the field is set to
undefined.Sandbox Link
What's your environment?
Other information
Code that sets the array to
undefinedif its length is zero: https://github.com/final-form/final-form-arrays/blob/fe3c260939cbdd446a48304dd2df0be2a1c41237/src/remove.js#L20C5-L22C18