selvagsz selvagsz - 1 month ago 42
React JSX Question

How to iterate over Map in immutablejs

What is the equivalent to

Object.entries()
in Immutablejs Map. Basically, I enumerate the object's key/value pairs to render a presentational component

{
Object.entries(filteredNetworks)
.map(([key, value]) =><option key={key} value={key}>{value}</option>)
}


Now, with the
filteredNetworks
being an immutable Map, how can i do the same ? (without using
.toJS()
)

Answer

Based on: https://facebook.github.io/immutable-js/docs/#/Iterable/map

{
  filteredNetworks.map(
  (value, key) => <option key={key} value={key}>{value}</option>
  )
}

note that argument order changed for the mapper function.

Another option using Entry Sequence could be

{
   filteredNetworks.entrySeq().map(
     .map(([key, value]) =><option key={key} value={key}>{value}</option>)
   )
}

fiddling around at https://jsfiddle.net/3r866to3/