Daejichu
Daejichu

Reputation: 57

TypeError: array.concat is not a functionRedux Form:FieldArray

I'm trying to develop a FieldArray within my Redux-Form, but run into the following error when I press the button 'Add Policy':

Uncaught TypeError: array.concat is not a function

My FieldArray calls a component:

<FieldArray name="policies" component={this.renderPolicies} />

The renderPolicies() helper function looks as follows:

renderPolicies = ({ fields, meta }) => {
return (
  <ul>
    <li>
      <button type="button" onClick={() => fields.push({})}>
        Add Policy
      </button>
      {this.renderError(meta)}
    </li>
    {fields.map((policy, index) => (
      <li key={index}>
        <button
          type="button"
          title="Remove Policy"
          onClick={() => fields.remove(index)}
        />
        <h4>Policy #{index + 1}</h4>
        <Field
          name={`${policy}.id`}
          type="text"
          component={renderInput}
          label="Id"
        />
      </li>
    ))}
  </ul>
);

};

Upvotes: 0

Views: 372

Answers (2)

MistyK
MistyK

Reputation: 6222

Just stumbled upon the same issue, make sure your arrayfield is not initialized to null, this is what happened to me

Upvotes: 1

Amrit Singh
Amrit Singh

Reputation: 1

What does your validation function look like? Take a look here: https://redux-form.com/8.1.0/examples/fieldarrays/.

Upvotes: 0

Related Questions