1

I'm trying to use Map objects in react state so that they both have key-value semantics and a defined order. It's not important what the order is, just that it be consistent so that objects don't keep moving around on re render, so insertion order works fine. The problem is that one of the patterns I keep reaching for is calling .map() on a piece of state with a function that returns a react component, but Map objects don't have .map() defined, only .forEach(). Is there any reason for this? it seems like .map() semantics should be pretty easy to define here.

Sam Schick
  • 400
  • 3
  • 14
  • So do it. You can add the `map` function to `Map`'s `prototype`. – Heretic Monkey Mar 03 '18 at 16:41
  • Because unfortunately no ES6 collections support [any iteration methods](https://stackoverflow.com/q/31232415/1048572) yet. `forEach` was just added as a simple way to access the entries if you don't want to go for an iterator. – Bergi Mar 03 '18 at 16:59

0 Answers0