mohan babu
mohan babu

Reputation: 1448

Redux-form field array , remove function throwing a weird error

Here is my scenario,

I have an array of objects which i am displaying through redux-form field array, that look something like

  [{
    index: 0,
    overlapRecord: '127.0.0.1'
  },
  {
    index: 1,
    overlapRecord: '127.0.0.1'
  }],

my code goes something like

<div className = "delete" onClick = {()=>field.remove(index)}> DeleteButton </div>

When i am trying to perform an On Click, I get the following error:

"Cannot use 'in' operator to search for 2 in" at deleteInWithPath.

Any Ideas on what would be the reason for the error can be highly appreciated.

Stack Trace: enter image description here

Upvotes: 0

Views: 484

Answers (2)

d4vsanchez
d4vsanchez

Reputation: 1994

I know I'm a bit late for this answer, but if someone else happens to have the same problem:

We had the same problem in our codebase, after a day or two looking for solutions we found that the problem was inside our validators.

We were returning:

const errors = {
  arrayFieldName: ''
};

And when changing it to:

const errors = {
  arrayFieldName: []
};

It worked correctly.

You can see in their Redux Form FieldArray Example, that they're returning an empty array in case there are no errors and there is information in the array, or an { _error: 'message' } if there is no data present.

Upvotes: 0

user8960351
user8960351

Reputation: 21

You need to give the on click event a callback Like

onclick={
 ()=>{
      field.remove(index)
     }
}

Upvotes: 2

Related Questions