Reputation: 3709
Storing Redux objects in the store by key/id makes them better for lookup, more easily modified, deleted, etc. It's also more efficient.
entities: {
3f9KwR2: {
first: 'John'
last: 'Johnson'
},
zyR4oLl: {
first: 'Tina'
...
I have noticed many people also storing a list of ids
in their reducer as well (example). In the case above, it would just be an array ['3f9KwR2', 'zyR4oLl']
.
This Redux recipe suggests keeping a list of ids solely to keep the original order of your data (how it is ordered in an API response, for example). If keeping the original order is not important, does storing a list of ids server any purpose?
Upvotes: 1
Views: 830
Reputation: 1498
No, it does not serve any purpose. The list of ids can be retrieved in your example with Object.keys(state.entities)
, except you know nothing about the order. If you do not care about the order, there is no difference between doing this and maintaining a separate list of ids.
Upvotes: 3