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

后端 未结 5 637
礼貌的吻别
礼貌的吻别 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

    Like @LeeByron said, you shouldn't have to call a toJS. Under React 0.14.*, calling map on an Immutable Map will work and render correctly, but you will end-up with a warning:

    Using Maps as children is not yet fully supported. It is an experimental feature that might be removed. Convert it to a sequence / iterable of keyed ReactElements instead.

    To deal with this, you can call toArray() on your Map like:

    render () {
      return (
        
    {this.props.immutableMap.toArray().map(item => {
    {item.title}
    })}
    ) }

    Converting your iterable to an array and giving React what it wants.

提交回复
热议问题