3

I am using redux-form with an FieldArray and I'm trying to create different renderings depending on which button is clicked on.

assuming I have the following function (which is in the component attribut of a FieldArray in a form):

const renderCatalogCategories = (props) => {

const { fields } = props;

return (
<div>
    {fields.map((data, idx) =>
       <Panel key={idx} header={`${data}.type`} data={data} />
    )}


    <DropdownButton>
       <MenuItem onClick={() => fields.push({type: 'a'})}>a</MenuItem>
       <MenuItem onClick={() => fields.push({type: 'b'})}>b</MenuItem>
    </DropdownButton>
</div>) 
};

It is not possible to get the value of type which I pass in the fields.push on the MenuItems. You have an idea how I can get this value?

The value of data I get is just a string, e.g. categories[9]

1 Answer 1

6

Well posed question. 👍

What you are looking for is fields.get(idx).

However, you will need the field name (what you have called data) to give to any <Field> component to edit your values inside the array.

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

1 Comment

fields.getAll() did the job too. Thanks!

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.