Skip to content

Commit 081b991

Browse files
committed
Docs: Enhance and correct selector memoization example in Essentials Part 6 (fixes #4820)
1 parent 9adc267 commit 081b991

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

docs/tutorials/essentials/part-6-performance-normalization.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -901,14 +901,20 @@ selectPostsByUser(state1, 'user2')
901901

902902
dispatch(reactionAdded())
903903
const state2 = getState()
904-
// Output selector does not run, because `posts` and `userId` are the same
904+
// Output selector runs, because the `posts` has changed
905905
selectPostsByUser(state2, 'user2')
906906

907907
// Add some more posts
908908
dispatch(addNewPost())
909909
const state3 = getState()
910910
// Output selector runs, because `posts` has changed
911911
selectPostsByUser(state3, 'user2')
912+
913+
// Fetch notifications
914+
dispatch(fetchNotifications())
915+
const state4 = getState()
916+
// Output selector does not run, because `posts` and `userId` are the same
917+
selectPostsByUser(state4, 'user2')
912918
```
913919
914920
Now that we've memoized `selectPostsByUser`, we can try repeating the React profiler with `<UserPage>` open while fetching notifications. This time we should see that `<UserPage>` doesn't re-render:

0 commit comments

Comments
 (0)