Advantages of using immutable.js over Object.assign or spread operators

前端 未结 6 965
天涯浪人
天涯浪人 2021-02-02 08:55

So far most of \"starter boilerplates\" and some posts about react / redux I\'ve seen encourage usage of immutable.js to address mutability. I personally rely on Object.as

6条回答
  •  再見小時候
    2021-02-02 09:54

    immutable.js gives you a lot of utilities that always return a new object.

    example:

    var Immutable = require('immutable');
    var map1 = Immutable.Map({a:1, b:2, c:3});
    var map2 = map1.set('b', 50);
    map1.get('b'); // 2
    map2.get('b'); // 50
    

    For just react / redux I personally think that Object.assign is powerful enought, but in some cases the use of that library could save you a few lines of code.

提交回复
热议问题