About the toJS method in immutable.js

  1. question

    when I use the toJS method in immutable to turn an array of immutable objects into a normal array, an error occurs

    error message: TypeError: list.toJS is not a function

    the confusing thing is that when I went to yarn start for the first time, he would not make a mistake. He would have it later, and it would be good to restart the server, and then make changes and hot updates and then report an error QAQ

    .
  2. list items

index Code

const newList = list.toJS();

reducer Code

const defaultState = fromJS({
  list: [1,2,3,4,5]
});

should be that you have changed list , and the changed list is not immutable data type. Take a look at the breakpoint


code from defaultState to list?


yarn start will be fine after I restart, which is very strange.


you should modify reducer by dispatch passing action . When you modify list , you should write state.set ("list", fromJS (action.data) , because the data passed by action will automatically become js objects instead of immutable objects, and need to be manually converted to immutable objects

.
Menu