Skip to content

Commit f382b34

Browse files
committed
Add docs
1 parent b162492 commit f382b34

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

docs/rtk-query/usage/customizing-create-api.mdx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import {
3535
reactHooksModule,
3636
} from '@reduxjs/toolkit/query/react'
3737

38-
const MyContext = React.createContext<ReactReduxContextValue>(null as any)
38+
const MyContext = React.createContext<ReactReduxContextValue | null>(null)
3939
const customCreateApi = buildCreateApi(
4040
coreModule(),
4141
reactHooksModule({
@@ -48,6 +48,27 @@ const customCreateApi = buildCreateApi(
4848
)
4949
```
5050

51+
## Customizing `createSelector` for RTKQ
52+
53+
Both `coreModule` and `reactHooksModule` accept a `createSelector` option which should be a selector creator instance from Reselect or with an equivalent signature.
54+
55+
```ts
56+
import * as React from 'react'
57+
import { createSelectorCreator, lruMemoize } from '@reduxjs/toolkit'
58+
import {
59+
buildCreateApi,
60+
coreModule,
61+
reactHooksModule,
62+
} from '@reduxjs/toolkit/query/react'
63+
64+
const createLruSelector = createSelectorCreator(lruMemoize)
65+
66+
const customCreateApi = buildCreateApi(
67+
coreModule({ createSelector: createLruSelector }),
68+
reactHooksModule({ createSelector: createLruSelector })
69+
)
70+
```
71+
5172
## Creating your own module
5273

5374
If you want to create your own module, you should review [the react-hooks module](https://github.com/reduxjs/redux-toolkit/blob/b74a52935a5840bebca5acdc8e2265e3b6497afa/src/query/react/module.ts) to see what an implementation would look like.

0 commit comments

Comments
 (0)