#StackBounty: #reactjs #redux #immutable.js React redux: Cannot set on an immutable record

Bounty: 100

I am trying to update my redux model from my reducer. The model is an extension of an Immutable Record class. I am trying to update the Record with the set method:

import { List, Record } from 'immutable';
import { IFaqItem } from './api.models';

export interface IFaqsState {
  loading?: boolean;
  items?: List<IFaqItem>;
}
const faqsState = Record({
  loading: false,
  items: List()
});

class FaqsState extends faqsState implements IFaqsState {
  loading: boolean;
  items: List<IFaqItem>;

  with(props: IFaqsState) {
    this.set('loading', props.loading);
    return this;
  }
}

export default FaqsState;

The reducer contains the following:

case ActionTypes.FAQS_GET_AJAX_RECEIVE:
  let response: IFaqsGetResponse = action.payload.response && action.payload.response.response;
  return state.with({
    loading: false,
    items: List(response)
  });

However this gives me the following error:

Error: Cannot set on an immutable record.

How do I solve this?


Get this bounty!!!