Redux: Documentation: es6 Map and Set in the state are not documented

Created on 8 Mar 2016  Â·  6Comments  Â·  Source: reduxjs/redux

I did not find in the documentation how one should or _should not_ use things like es6 Map and Set with Redux.

It seems like a new map should be created every time when we 'modify' it in the reducer, but I'm not sure that it is correct.

Most helpful comment

I don’t think it’s a good idea to use them in Redux because they are optimized for mutability. If you want to have something efficient with similar semantics, consider using Immutable.js.

All 6 comments

I don’t think it’s a good idea to use them in Redux because they are optimized for mutability. If you want to have something efficient with similar semantics, consider using Immutable.js.

Can this be mentioned somewhere in the docs, that it is not a good idea? (probably this issue is enough to be googled by keywords)

Yes, I'm not able to use ES6 map it seems it just deal with Objects, and array only.

You _can_ use Maps and Sets as state values, but it's not recommended due to serializability concerns. In addition, the built-in combineReducers utility expects to work with plain JS objects, so if you use a Map as part of your state tree, you would need to use other reducer handling instead of combineReducers.

Not sure if this is what @markerikson means by "serializability concerns", but for example if you try to do things like export/import your entire state with json, any maps in your reducer state will not properly be initialized. The basic issue is outlined here: http://2ality.com/2015/08/es6-map-json.html

Was this page helpful?
0 / 5 - 0 ratings

Related issues

caojinli picture caojinli  Â·  3Comments

ilearnio picture ilearnio  Â·  3Comments

ms88privat picture ms88privat  Â·  3Comments

mickeyreiss-visor picture mickeyreiss-visor  Â·  3Comments

timdorr picture timdorr  Â·  3Comments