question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FieldArray fields.length not showing actual size of fields.length

See original GitHub issue

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, 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:closed
  • Created 7 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
markaucommented, Dec 15, 2016

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.

0reactions
lock[bot]commented, Dec 7, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found