5
isMain = (v, k) => {

    let {avatars: {fields}, push} = this.props;

    fields.getAll().map((avatar, key) => {

      fields.remove(key);

      push('avatars', {
        deleteImage: avatar.deleteImage || false,
        uuid: avatar.uuid,
        fileName: avatar.fileName,
        url: avatar.url,
        setMain: key === k,
      });

    });

};

This is how I try^ Doesn't work, I don't know why

I use v6

I also tried insert

But with insert field not removed only - copied! Although the value of new fields changed

1 Answer 1

11

if you only want to update a single item in array avatars, an alternative solution is using redux-form's Action Creators. Just need to provide the index value to action:

import { change } from 'redux-form'
...
setMain: (k) => dispatch(change(`yourForm`, `avatars[${k}].setMain`, true))

You can create another action removeMain(k) in the same manner to remove the old main avatar item.

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

1 Comment

I can't import the change function, while I can import the others just fine (Field, Fields, formValueSelector). It shows this error: Module not found: Error: Can't resolve 'redux-form/es/change'

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.