React redux: Cannot set on an immutable record

React redux: Cannot set on an immutable record

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:

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.

UPDATE

When I change the reducer from:

let initial = new FaqsState();

const faqsReducer: Reducer<FaqsState> = (state = initial, action: AppActions) => {

to:

const faqsReducer: Reducer<FaqsState> = (state = null, action: AppActions) => {

state = new FaqsState();

it seems to work. Why is it not working when I give the initial state in as an argument?

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

An intro to Redux and how state is updated in a Redux application

I started learning Redux a few days back and it was an overwhelming concept for me at the start. After polishing my skills in ReactJS by making a&nbsp;<a href="https://github.com/aimenbatool/my-reads" target="_blank">personal book reading application</a>, I headed towards Redux to learn more about it.

React Boilerplates with Redux, Redux Saga and Best Practices

React Boilerplates with Redux, Redux Saga and Best Practices