You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/api/createSlice.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -353,7 +353,7 @@ reducers: (create) => {
353
353
354
354
### `extraReducers`
355
355
356
-
Conceptually, each slice reducer "owns" its slice of state. There's also a natural correspondance between the update logic defined inside `reducers`, and the action types that are generated based on those.
356
+
Conceptually, each slice reducer "owns" its slice of state. There's also a natural correspondence between the update logic defined inside `reducers`, and the action types that are generated based on those.
357
357
358
358
However, there are many times that a Redux slice may also need to update its own state in response to action types that were defined elsewhere in the application (such as clearing many different kinds of data when a "user logged out" action is dispatched). This can include action types defined by another `createSlice` call, actions generated by a `createAsyncThunk`, RTK Query endpoint matchers, or any other action. In addition, one of the key concepts of Redux is that many slice reducers can independently respond to the same action type.
Copy file name to clipboardExpand all lines: docs/rtk-query/api/created-api/hooks.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -370,7 +370,7 @@ selectFromResult: () => ({})
370
370
- `trigger`: A function that triggers an update to the data based on the provided argument. The trigger function returns a promise with the properties shown above that may be used to handle the behavior of the promise
371
371
- `mutationState`: A query status object containing the current loading state and metadata about the request, or the values returned by the `selectFromResult` option where applicable.
372
372
Additionally, this object will contain
373
-
- a `reset` method to reset the hook back to it's original state and remove the current result from the cache
373
+
- a `reset` method to reset the hook back to its original state and remove the current result from the cache
374
374
- an `originalArgs` property that contains the argument passed to the last call of the `trigger` function.
Copy file name to clipboardExpand all lines: docs/usage/usage-with-typescript.md
+31-5Lines changed: 31 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -724,20 +724,46 @@ Import and use that pre-typed `createAppAsyncThunk` instead of the original, and
724
724
725
725
## `createEntityAdapter`
726
726
727
-
Typing `createEntityAdapter`only requires you to specify the entity type as the single generic argument.
727
+
Usage of `createEntityAdapter`with Typescript varies based on whether your entities are normalized by an `id` property, or whether a custom `selectId` is needed.
728
728
729
-
The example from the `createEntityAdapter`documentation would look like this in TypeScript:
729
+
If your entities are normalized by an `id` property, `createEntityAdapter`only requires you to specify the entity type as the single generic argument. For example:
730
730
731
731
```ts
732
732
interfaceBook {
733
-
bookId:number
733
+
id:number
734
734
title:string
735
-
// ...
736
735
}
737
736
737
+
// no selectId needed here, as the entity has an `id` property we can default to
738
738
// highlight-next-line
739
739
const booksAdapter =createEntityAdapter<Book>({
740
-
selectId: (book) =>book.bookId,
740
+
sortComparer: (a, b) =>a.title.localeCompare(b.title),
On the other hand, if the entity needs to be normalized by a different property, we instead recommend passing a custom `selectId` function and annotating there. This allows proper inference of the ID's type, instead of having to provide it manually.
756
+
757
+
```ts
758
+
interfaceBook {
759
+
bookId:number
760
+
title:string
761
+
// ...
762
+
}
763
+
764
+
const booksAdapter =createEntityAdapter({
765
+
// highlight-next-line
766
+
selectId: (book:Book) =>book.bookId,
741
767
sortComparer: (a, b) =>a.title.localeCompare(b.title),
0 commit comments