final-form / final-form/react-final-form-arrays
Manually calling field.push generates 2 elements in FieldArray
- Dominant language
- TypeScript
- Stars
- 210
- Forks
- 69
- PR merge metrics
- No merged PRs in 30d
Description
### Are you submitting a **bug report** or a **feature request**?
I'm submitting a **bug report**.
### What is the current behavior?
**FieldArray** initializes empty, if I manually call `fields.push("")` only when `fields.length` is zero, it should add only one element, but, it's adding 2 elements.
Here is a codesandbox to show the behaviour: https://codesandbox.io/s/react-final-form-arrays-bug-cww5f
### What is the expected behavior?
If I call `fields.push("")` validating that `fields.length` is zero, it should add only one element to the array, not two.
### Sandbox Link
https://codesandbox.io/s/react-final-form-arrays-bug-cww5f
### What's your environment?
- **React Final Form Arrays:** v3.1.1
- **React Final Form:** v.6.3.0
- **Final Form Arrays:** v3.0.1
- **Final Form:** v4.18.5
- **OS:** Mac OS Mojave v10.14.6
- **Browser:** Chrome/Firefox/Safari
- **Node Version:** v11.12.0
### Other information
I have done a little of debugging and it seems an issue related to the function `changeValue `injected by the mutator. When I call `fields.push("")` for first time, it does not change the value, because it doesn't change the value, in the second iteration the array length is still zero.
In the second iteration, it seems that the value is correctly updated, but, because it has been called two times to produce an update, the array now has two elements.
Contributor guide
Assessment
This issue has not been assessed yet.