Skip to content

Understanding createSlice + selectors + memoization Current State #4553

Closed Answered by EskiMojo14
jd-carroll asked this question in Q&A
Discussion options

You must be logged in to vote

Hi there!

My understanding is that every time I reference authSlice.selectors it will "instantiate" (?) a new selectors object and pass the current slice state as the first parameter.

This is not the case - the first time .selectors is referenced, it'll make a wrapped version of the selectors object. Every time after that it'll return the same cached object. The same goes for getSelectors(selectSlice) - if the same selectSlice callback is passed, it'll return the same object.

How do I memoize the selector result? I thought that there was already some "auto-magic" that happened behind the scenes where the state is memoized and because that is memoized it does not need to re-run the sele…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by jd-carroll
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants