Skip to content

Commit 3f82d47

Browse files
committed
update docs with new options
1 parent 8c1a64f commit 3f82d47

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

docs/usage/custom-slice-creators.mdx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,10 +429,12 @@ A creator only needs a `handle` callback if it expects to be called with reducer
429429

430430
It receives three arguments: details about the reducer, the definition, and a `context` object with methods to modify the slice.
431431

432-
The reducer details object has two properties:
432+
The reducer details object has the following properties:
433433

434+
- `sliceName` - the name of the slice the reducer is being added to (e.g. `entities/todos`)
435+
- `reducerPath` - the `reducerPath` passed to `createSlice` (e.g. `todos`) (defaults to `sliceName` if not provided)
434436
- `reducerName` - the key the reducer definition was under (e.g. `addTodo`)
435-
- `type` - the automatically generated type string for the reducer (e.g. `todos/addTodo`)
437+
- `type` - the automatically generated type string for the reducer (e.g. `entities/todos/addTodo`)
436438

437439
The context object includes:
438440

@@ -484,6 +486,19 @@ context
484486
.exposeCaseReducer(resetReducer)
485487
```
486488

489+
#### `selectSlice`
490+
491+
Tries to select the slice's state from the root state, using the original `reducerPath` option passed when calling `createSlice` (which defaults to the `name` option). Throws an error if it can't find the slice.
492+
493+
```ts
494+
const aThunk =
495+
(): ThunkAction<void, Record<string, unknown>, unknown, Action> =>
496+
(dispatch, getState) => {
497+
const state = context.selectSlice(getState())
498+
// do something with state
499+
}
500+
```
501+
487502
### Typescript
488503

489504
The Typescript system for custom slice creators uses a "creator registry" system similar to the module system for [RTK Query](/rtk-query/usage/customizing-create-api#creating-your-own-module).
@@ -512,6 +527,7 @@ The type parameters for `SliceReducerCreators` are:
512527
- `State` - The state type used by the slice.
513528
- `CaseReducers` - The case reducer definitions returned by the creator callback.
514529
- `Name` - The [`name`](../api/createSlice#name) used by the slice.
530+
- `ReducerPath` - The [`reducerPath`](../api/createSlice#reducerpath) used by the slice.
515531

516532
The `ReducerCreatorEntry<Create, Exposes>` utility has two type parameters:
517533

0 commit comments

Comments
 (0)