Skip to content

Commit bf4d621

Browse files
committed
Added withTypes documentation and re-enabled table of contents for this doc
1 parent e26d87e commit bf4d621

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

docs/api/createSelector.mdx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ hide_title: true
99

1010
# `createSelector`
1111

12+
## Overview
13+
1214
The `createSelector` utility from the [Reselect library](https://github.com/reduxjs/reselect), re-exported for ease of use.
1315

1416
For more details on using `createSelector`, see:
@@ -24,7 +26,7 @@ allowed using string keypaths as input selectors. This was removed, as it ultima
2426
the string keypaths made static typing for selectors difficult.
2527
:::
2628

27-
# `createDraftSafeSelector`
29+
## `createDraftSafeSelector`
2830

2931
In general, we recommend against using selectors inside of reducers:
3032

@@ -86,3 +88,14 @@ const draftSafeSelector = createWeakMapDraftSafeSelector(
8688
```
8789

8890
:::
91+
92+
### Defining a Pre-Typed `createDraftSelector`
93+
94+
As of RTK 2.1, you can define a "pre-typed" version of `createDraftSafeSelector` that can have the type for `state` built in. This lets you set up those types once, so you don't have to repeat them each time you call `createDraftSafeSelector`.
95+
96+
```ts no-transpile
97+
const createTypedDraftSafeSelector = createDraftSafeSelector.withTypes<RootState>()
98+
```
99+
100+
Import and use the pre-typed `createTypedDraftSafeSelector` function, and it will automatically know that the `state` argument is of type `RootState`.
101+

0 commit comments

Comments
 (0)