0

I'm trying to create FieldArray. I got sth like this:

<form>
  <FieldArray
    name="styles"
    component={this.renderStyles}
  />
</form>

and then:

renderStyles = (props) => {
  return(
    <ul>
    {props.fields.map((style, index) =>{
    console.log(style)
    return(
      <li key={style} className="field-item">
        <label>{style}</label>
        <Field
            name={`${style}`}
            component="input"
            type="checkbox"
        />
      </li>)
  }
)} 
</ul>
)}

I also do initialize the values for FieldArray like this:

initialValues:{styles:[{style:'somestyle', img:'someimgurl'}]}

However the console.log(style) in renderStyles showes me only styles[0] as a string. No way to obtain the object. I tried different ways. HELP DERP! Please :)

2
  • ok, never mind. After hours of tortures props.fields.getAll().map... does the trick finally... Isn't it a bug in FieldArray though? Commented Jan 23, 2018 at 20:30
  • Put that as an answer then and mark it as such. Commented Jan 23, 2018 at 20:30

1 Answer 1

1

ok, never mind. After hours of tortures props.fields.getAll().map... does the trick finally... Isn't it a bug in FieldArray though?

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

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.