Skip to content

Commit a9e3fa4

Browse files
committed
make sure each creator symbol has a description
1 parent c2523fc commit a9e3fa4

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

docs/usage/custom-slice-creators.mdx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ const todoSlice = createSlice({
390390
The `type` property of the definition should be the same constant used for reducer definitions to be handled by this creator. To avoid collision, we recommend using Symbols for this. It's also used for defining/retrieving types - see [Typescript](#typescript).
391391

392392
```ts no-transpile
393-
const reducerCreatorType = Symbol()
393+
const reducerCreatorType = Symbol('reducerCreatorType')
394394

395395
const reducerCreator: ReducerCreator<typeof reducerCreatorType> = {
396396
type: reducerCreatorType,
@@ -506,7 +506,7 @@ The Typescript system for custom slice creators uses a "creator registry" system
506506
Creators are registered by using module augmentation to add a new key (their unique `type`) to the `SliceReducerCreators` interface. The interface receives three type parameters (`State`, `CaseReducers` and `Name`), and each entry should use the `ReducerCreatorEntry` type utility.
507507

508508
```ts no-transpile
509-
const reducerCreatorType = Symbol()
509+
const reducerCreatorType = Symbol('reducerCreatorType')
510510

511511
declare module '@reduxjs/toolkit' {
512512
export interface SliceReducerCreators<
@@ -548,7 +548,7 @@ Assuming the creator is called as `create.yourCreator()`, the `this` value for t
548548
However, this should be specifically included in the function signature, so Typescript can warn if called with an incorrect context (for example, if the user destructures from the `create` value).
549549

550550
```ts no-transpile
551-
const batchedCreatorType = Symbol()
551+
const batchedCreatorType = Symbol('batchedCreatorType')
552552

553553
declare module '@reduxjs/toolkit' {
554554
export interface SliceReducerCreators<
@@ -587,7 +587,7 @@ The second argument to the `ReducerCreators` type is a map from creator names to
587587
Sometimes it's useful to have a reducer creator that only works with a specific state shape. You can ensure the creator is only callable if the state matches, using a conditional type:
588588

589589
```ts no-transpile
590-
const loaderCreatorType = Symbol()
590+
const loaderCreatorType = Symbol('loaderCreatorType')
591591

592592
declare module '@reduxjs/toolkit' {
593593
export interface SliceReducerCreators<
@@ -614,7 +614,7 @@ Any creators that evaluate to the `never` type are omitted from the final `creat
614614
An alternative would be just using that required type _as_ the `State` type for the reducer definitions, so Typescript then complains when the creator is used.
615615

616616
```ts no-transpile
617-
const loaderCreatorType = Symbol()
617+
const loaderCreatorType = Symbol('loaderCreatorType')
618618

619619
declare module '@reduxjs/toolkit' {
620620
export interface SliceReducerCreators<
@@ -656,7 +656,7 @@ In order to ensure that the definitions are correctly filtered to only include t
656656
For example, with (a simplified version of) the `asyncThunk` creator:
657657

658658
```ts no-transpile
659-
const asyncThunkCreatorType = Symbol()
659+
const asyncThunkCreatorType = Symbol('asyncThunkCreatorType')
660660

661661
declare module '@reduxjs/toolkit' {
662662
export interface SliceReducerCreators<
@@ -694,7 +694,7 @@ Similar to `actions`, except for `slice.caseReducers`.
694694
For example, with the `preparedReducer` creator:
695695

696696
```ts no-transpile
697-
const preparedReducerType = Symbol()
697+
const preparedReducerType = Symbol('preparedReducerType')
698698

699699
declare module '@reduxjs/toolkit' {
700700
export interface SliceReducerCreators<
@@ -771,7 +771,7 @@ One example would be reusable toast logic; you could have a reducer creator that
771771

772772
```ts no-transpile
773773
// create the unique type
774-
const toastCreatorType = Symbol()
774+
const toastCreatorType = Symbol('toastCreatorType')
775775

776776
interface Toast {
777777
message: string
@@ -926,7 +926,7 @@ A creator could also return multiple definitions, which would then be spread int
926926
One example could be returning some pagination related reducers.
927927

928928
```ts no-transpile
929-
const paginationCreatorType = Symbol()
929+
const paginationCreatorType = Symbol('paginationCreatorType')
930930

931931
interface PaginationState {
932932
page: number
@@ -990,7 +990,7 @@ const { prevPage, nextPage, goToPage, toggleLoading } = paginationSlice.actions
990990
A creator could return a mix of reducer definitions for itself and other creators to handle:
991991

992992
```ts no-transpile
993-
const historyCreatorType = Symbol()
993+
const historyCreatorType = Symbol('historyCreatorType')
994994

995995
interface PatchesState {
996996
undo: Patch[]
@@ -1111,7 +1111,7 @@ Following on from the `HistoryState` example above, it would be useful to make s
11111111
Fortunately, this is possible with a creator:
11121112

11131113
```ts no-transpile
1114-
const undoableCreatorType = Symbol()
1114+
const undoableCreatorType = Symbol('undoableCreatorType')
11151115

11161116
interface UndoableMeta {
11171117
undoable?: boolean

0 commit comments

Comments
 (0)