I have an array of post objects that is stored in redux. I am mapping over the posts, and passing the ID and index to the Post component:
posts.map((post, index) => {
<Post id={post.id} index={index} />
});
The redux style guide states:
Prefer having more UI components subscribed to the Redux store and reading data at a more granular level...
For example, rather than just connecting a
<UserList>component and reading the entire array of users, have<UserList>retrieve a list of all user IDs, render list items as<UserListItem userId={userId}>, and have<UserListItem>be connected and extract its own user entry from the store.
However, I do not have a list of postIds, but I am still trying to get more components subscribed by mapping over the posts and passing a reference to the post component, instead of the post itself. (Is that a good idea?)
My question is regarding how I should read the post from the store. Whether by ID or by Index:
- post = state.posts.find(post => post.id === props.id)
- post = state.posts[props.index]
Obviously, reading by index will be much, much faster. But the posts array can be reordered. So I want to know if the index created by the map function is dependable?