Docs: Enhance and correct selector memoization example in Essentials Part 6 #4821
+7
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fixes #4820
This PR updates the code example in Part 6 of the Redux Essentials tutorial ("Memoizing Selector Functions") to be technically accurate and better aligned with the section's teaching goals.
The previous example had two issues which are addressed here:
Technical Correction (reactionAdded): The example previously claimed the selector did not run after reactionAdded(). Because this action changes a post (and thus the parent posts array reference via Immer), the selector's input does change. This PR corrects the assertion to state that the output selector runs.
Pedagogical Enhancement (fetchNotifications): The core of this tutorial section is about preventing re-renders from unrelated state changes (like fetching notifications). The new block includes dispatch(fetchNotifications()) to provide the clear example that the memoized selector does not run when only an unrelated slice changes.
The revised example now covers all four key memoization scenarios clearly.
(Technical Note: Stating that the output selector runs is the most accurate description of the internal memoization logic in this context, even if the eventual component re-render might be prevented by a more complex equal function (which isn't the primary focus here). This was my thought process, although at first I explicitly stated this in the example, it cluttered the example and I came to the conclusion that it could potentially cause more confusion rather than helping the reader.)