Skip to content

Commit 2b4f6db

Browse files
committed
Add section about performance impact of idempotent selectors
1 parent eca674f commit 2b4f6db

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

docs/typescript.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1149,4 +1149,6 @@ Enabling composed selectors to accept different, even disjoint state types resol
11491149
> [!NOTE]
11501150
> At runtime, all selectors are passed the entire Redux state, which is always assignable to the narrower state argument type.
11511151
>
1152-
> Following this guideline does not affect selector memoization. As `Object.assign` and spread syntax perform a shallow copy operation, the references of nested composite data structures are not mutated when a state object is passed into a selector function. This makes cache invalidation a non-concern.
1152+
> Following this guideline does not affect selector memoization. When background state updates are dispatched to the Redux store, the Redux state object is shallow copied. This does not mutate the references of nested composite data structures, which makes cache invalidation a non-concern.
1153+
>
1154+
> The only exception to this is an idempotent selector that returns the entire Redux state (e.g. `(state: RootState) => state`). This pattern should be avoided if possible, as it will cause a performance hit to any downstream selector.

0 commit comments

Comments
 (0)