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
Typically, you should only have one API slice per base URL that your application needs to communicate with. For example, if your site fetches data from both `/api/posts` and `/api/users`, you would have a single API slice with `/api/` as the base URL, and separate endpoint definitions for `posts` and `users`. This allows you to effectively take advantage of [automated re-fetching](../usage/automated-refetching.mdx) by defining [tag](../usage/automated-refetching.mdx#tags) relationships across endpoints.
18
18
19
+
This is because:
20
+
21
+
- Automatic tag invalidation only works within a single API slice. If you have multiple API slices, the automatic invalidation won't work across them.
22
+
- Every `createApi` call generates its own middleware, and each middleware added to the store will run checks against every dispatched action. That has a perf cost that adds up. So, if you called `createApi` 10 times and added 10 separate API middleware to the store, that will be noticeably slower perf-wise.
23
+
19
24
For maintainability purposes, you may wish to split up endpoint definitions across multiple files, while still maintaining a single API slice which includes all of these endpoints. See [code splitting](../usage/code-splitting.mdx) for how you can use the `injectEndpoints` property to inject API endpoints from other files into a single API slice definition.
Copy file name to clipboardExpand all lines: docs/rtk-query/api/created-api/overview.mdx
+5Lines changed: 5 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,6 +19,11 @@ This section documents the contents of that API structure, with the different fi
19
19
20
20
Typically, you should only have one API slice per base URL that your application needs to communicate with. For example, if your site fetches data from both `/api/posts` and `/api/users`, you would have a single API slice with `/api/` as the base URL, and separate endpoint definitions for `posts` and `users`. This allows you to effectively take advantage of [automated re-fetching](../../usage/automated-refetching.mdx) by defining [tag](../../usage/automated-refetching.mdx#tags) relationships across endpoints.
21
21
22
+
This is because:
23
+
24
+
- Automatic tag invalidation only works within a single API slice. If you have multiple API slices, the automatic invalidation won't work across them.
25
+
- Every `createApi` call generates its own middleware, and each middleware added to the store will run checks against every dispatched action. That has a perf cost that adds up. So, if you called `createApi` 10 times and added 10 separate API middleware to the store, that will be noticeably slower perf-wise.
26
+
22
27
For maintainability purposes, you may wish to split up endpoint definitions across multiple files, while still maintaining a single API slice which includes all of these endpoints. See [code splitting](../../usage/code-splitting.mdx) for how you can use the `injectEndpoints` property to inject API endpoints from other files into a single API slice definition.
Copy file name to clipboardExpand all lines: docs/rtk-query/api/fetchBaseQuery.mdx
+14-2Lines changed: 14 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -64,7 +64,7 @@ type FetchBaseQueryArgs = {
64
64
api:Pick<
65
65
BaseQueryApi,
66
66
'getState'|'extra'|'endpoint'|'type'|'forced'
67
-
>,
67
+
>& { arg:string|FetchArgs },
68
68
) =>MaybePromise<Headers|void>
69
69
fetchFn?: (
70
70
input:RequestInfo,
@@ -105,7 +105,7 @@ Typically a string like `https://api.your-really-great-app.com/v1/`. If you don'
105
105
106
106
_(optional)_
107
107
108
-
Allowsyoutoinjectheadersoneveryrequest. Youcanspecifyheadersattheendpointlevel, butyou'll typically want to set common headers like `authorization` here. As a convenience mechanism, the second argument allows you to use `getState` to access your redux store in the event you store information you'llneedtheresuchasanauthtoken. Additionally, itprovidesaccessto`extra`, `endpoint`, `type`, and`forced`tounlockmoregranularconditionalbehaviors.
108
+
Allowsyoutoinjectheadersoneveryrequest. Youcanspecifyheadersattheendpointlevel, butyou'll typically want to set common headers like `authorization` here. As a convenience mechanism, the second argument allows you to use `getState` to access your redux store in the event you store information you'llneedtheresuchasanauthtoken. Additionally, itprovidesaccessto`arg`, `extra`, `endpoint`, `type`, and`forced`tounlockmoregranularconditionalbehaviors.
Bydefault, `fetchBaseQuery`will`reject`any`Response`thatdoesnothaveastatuscodeof`2xx`andsetitto`error`. Thisisthesamebehavioryou've most likely experienced with `axios` and other popular libraries. In the event that you have a non-standard API you'redealingwith, youcanusethe`validateStatus`optiontocustomizethisbehavior.
Copy file name to clipboardExpand all lines: docs/usage/immer-reducers.md
+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
@@ -150,7 +150,7 @@ Writing immutable update logic by hand _is_ hard, and **accidentally mutating st
150
150
Immer provides a function called `produce`, which accepts two arguments: your original `state`, and a callback function. The callback function is given a "draft" version of that state, and inside the callback, it is safe to write code that mutates the draft value. Immer tracks all attempts to mutate the draft value and then replays those mutations using their immutable equivalents to create a safe, immutably updated result:
0 commit comments