In React, suppose you have a component that is going to display a list.
Which is the more React/Redux compliant method for passing the list to the component?
- Pass an array of objects
- Pass an array of keys only, plus a map (dictionary) to look up the object
e.g.:
<ListComponent data={objectArray} />
vs.
<ListComponent keyArray={keyArray} dictionary={mapOfKeyToObject} />
Please consider performance, reusability, accepted conventions and testing.
thanks
EDIT: To clarify, I mean keys as in ID fields of the objects (not talking about the keys that React uses for identifying in rendering).
The question is related to [https://redux.js.org/basics/reducers#note-on-relationships]:
In a more complex app, you're going to want different entities to reference each other. We suggest that you keep your state as normalized as possible, without any nesting. Keep every entity in an object stored with an ID as a key, and use IDs to reference it from other entities, or lists. ... For example, keeping todosById: { id -> todo } and todos: array inside the state would be a better idea in a real app.
So is it better then to pass that dictionary to the component (e.g. todosById) plus a second array with just the keys/IDs to display vs. have a subset array that's just the objects?
Consider that those objects might be getting updated by other components.