0

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>
);

};

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

This seemed to fix the issue. Not 100% sure the mechanics behind it, but thank you SO much!.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.