Himmel Himmel - 1 year ago 69
Javascript Question

Keep a list of ids in Redux store

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
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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download