When to use .toJS() with Immutable.js and Flux?

后端 未结 5 639
礼貌的吻别
礼貌的吻别 2021-01-30 16:38

I\'m trying to use ImmutableJS with my React / Flux application.

My stores are Immutable.Map objects.

I\'m wondering at which point should I use

5条回答
  •  执念已碎
    2021-01-30 17:09

    Good point raised by @Hummlas.

    I personnally use it in my React components, when I iterate over a collections to render an array of sub components:

    this.props.myImmutableCollection.map(function(item, index) {
        React.DOM.div null, item.get('title');
    }).toJS();
    

    If you don't use .toJS(), React won't recognize the mapped elements as an array of components.

提交回复
热议问题