Redux - Why normalize?

后端 未结 2 1341
借酒劲吻你
借酒劲吻你 2021-02-02 14:15

I have been trying to learn how to better structure my Redux stores and stumbled upon this lesson by Dan.

https://egghead.io/lessons/javascript-redux-normalizing-the-sta

2条回答
  •  隐瞒了意图╮
    2021-02-02 14:39

    Why do we need to maintain a list of allIds? Why maintain this additional state, when we can easily map over the list of all todos and obtain it?

    Storing an array of IDs allows us to define an order for the items. While JS engines now have a fairly standardized process for iterating across keys in an object, you shouldn't rely on that to define ordering.

    Answer thanks to markerikson

提交回复
热议问题