Smokovsky
Smokovsky

Reputation: 562

Question in Redux's doc with regard to createSelector and createEntityAdapter

On the page: doc

This section: enter image description here states that dispatch(reactionAdded()) won't cause the component to re-render as posts is not changed here. But it seems reactionAdded does mutate one of the posts cause the entire posts array to be replaced by a new one.

Another question: enter image description here Does it mean value returned by selectById selectIds from createEntityAdapter will always return the same array(unchanged reference) as long as all ids of entity are unchanged even if content of entities memeber is changed?

Upvotes: 1

Views: 364

Answers (1)

markerikson
markerikson

Reputation: 67459

Hmm. I wrote that tutorial, and it's entirely possible I made a mental mistake when writing that example. Yeah, reactionAdded does update a post entry, which would also mean that there should be a new posts array generated as a result because of the immutable updates. Probably need to come up with a different example there :)

And yes, selectById always does a straight lookup - ie, return state.posts.entities[postId], so there's no derived data involved. It just returns that one item by itself.

Upvotes: 1

Related Questions