Reputation: 1448
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.
Upvotes: 0
Views: 484
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
Reputation: 21
You need to give the on click event a callback Like
onclick={
()=>{
field.remove(index)
}
}
Upvotes: 2