FieldArray fields.length not showing actual size of fields.length
See original GitHub issueI have a FieldArray, and I want to swap fields in it using fields.swap(indexA, indexB), and buttons insiede Field
The swap forks fine, but I meet problems when I want to check the length of fields I receive as props. This length is always equal to the index of the item I clicked on. (If I clicked on first item - fields.length will equal 1, tenth - ten, even though there are 20 items in fields array)
simplified version of my code is this. Am I doing something wrong, or is there an issue with redux-form?
<FieldArray name="Fields" component={renderFields} />
...
const renderFields= ({ fields, meta: { error } }) => {
const handleSwap = function (currentIndex, nextIndex) {
//This next line is where I meet the problem
//fields.length is always equal to the index of item I clicked
if(nextIndex < fields.length )
{
fields.swap(currentIndex, nextIndex)
}
}
return (
<div>
{fields.map((field, index) =>
<Field
onSwap={handleSwap}
....
</Field>
</div>
)
}
may be the problem is with how I define handleSwap in the render function?
P.S. Thanks for an amazing library
Issue Analytics
- State:
- Created 7 years ago
- Comments:6
Top Results From Across the Web
FieldArray fields.length not showing actual size of ...
I have a FieldArray, and I want to swap fields in it using fields.swap(indexA, indexB), and buttons insiede Field The swap forks fine, ......
Read more >reactjs - FieldArray fields.length not showing actual size of ...
simplified version of my code is this. Am I doing something wrong, or is there an issue with redux-form? <FieldArray name="Fields" component={ ...
Read more >FieldArray
The FieldArray component is how you render an array of fields. It works a lot like Field . ... fields.length : Number #....
Read more >Types of fields and field data - Dynamics 365
Field data can include lines of text, currency, dates and times, images and more. ... You can set the maximum length to be...
Read more ><FieldArray /> | Formik
Validation can be tricky with <FieldArray> . If you use validationSchema and your form has array validation requirements (like a min length) as...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This doesn’t help you directly, but I can confirm that fields.length works correctly for me in my project. (v6.3.2)
Refactoring to the pattern in #2187 might be worth a try.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.