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
Using this together with an existing redux store will cause them to conflict with each other. If you are already using Redux, please use follow the instructions as shown in the [Getting Started guide](../introduction/getting-started).
15
+
Using this together with an existing Redux store will cause them to conflict with each other. If you are already using Redux, please use follow the instructions as shown in the [Getting Started guide](../../introduction/getting-started).
Copy file name to clipboardExpand all lines: docs/api/rtk-query/createApi.md
+86-34Lines changed: 86 additions & 34 deletions
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,31 @@ hide_title: true
7
7
8
8
# `createApi`
9
9
10
-
The main point where you will define a service to use in your application.
10
+
`createApi` is the core of RTK Query's functionality. It allows you to define a set of endpoints describe how to retrieve data from a series of endpoints, including configuration of how to fetch and transform that data. It generates [an "API slice" structure](./created-api/overview.md) that contains Redux logic (and optionally React hooks) that encapsulate the data fetching and caching process for you.
11
+
12
+
```ts title="Example: src/services/pokemon.ts"
13
+
// Need to use the React-specific entry point to allow generating React hooks
-`onStart`, `onError` and `onSuccess`_(optional)_ - Available to both [queries](../concepts/queries) and [mutations](../concepts/mutations)
88
-
- Can be used in`mutations`for [optimistic updates](../concepts/optimistic-updates).
117
+
-`onStart`, `onError` and `onSuccess`_(optional)_ - Available to both [queries](../../usage/rtk-query/queries.md) and [mutations](../../usage/rtk-query/mutations.md)
118
+
- Can be used in`mutations`for [optimistic updates](../../usage/rtk-query/optimistic-updates.md).
89
119
-```ts title="Mutation lifecycle signatures"
90
-
function onStart(arg: QueryArg, mutationApi: MutationApi<ReducerPath, Context>): void;
91
-
function onError(arg: QueryArg, mutationApi: MutationApi<ReducerPath, Context>, error: unknown): void;
92
-
function onSuccess(arg: QueryArg, mutationApi: MutationApi<ReducerPath, Context>, result: ResultType): void;
120
+
function onStart(
121
+
arg: QueryArg,
122
+
mutationApi: MutationApi<ReducerPath, Context>
123
+
): void
124
+
function onError(
125
+
arg: QueryArg,
126
+
mutationApi: MutationApi<ReducerPath, Context>,
127
+
error: unknown
128
+
): void
129
+
function onSuccess(
130
+
arg: QueryArg,
131
+
mutationApi: MutationApi<ReducerPath, Context>,
132
+
result: ResultType
133
+
): void
93
134
```
94
135
-```ts title="Query lifecycle signatures"
95
-
function onStart(arg: QueryArg, queryApi: QueryApi<ReducerPath, Context>): void;
96
-
function onError(arg: QueryArg, queryApi: QueryApi<ReducerPath, Context>, error: unknown): void;
97
-
function onSuccess(arg: QueryArg, queryApi: QueryApi<ReducerPath, Context>, result: ResultType): void;
136
+
function onStart(
137
+
arg: QueryArg,
138
+
queryApi: QueryApi<ReducerPath, Context>
139
+
): void
140
+
function onError(
141
+
arg: QueryArg,
142
+
queryApi: QueryApi<ReducerPath, Context>,
143
+
error: unknown
144
+
): void
145
+
function onSuccess(
146
+
arg: QueryArg,
147
+
queryApi: QueryApi<ReducerPath, Context>,
148
+
result: ResultType
149
+
): void
98
150
```
99
151
100
152
#### How endpoints get used
@@ -140,14 +192,14 @@ By default, the payload from the server is returned directly.
140
192
141
193
```ts
142
194
function defaultTransformResponse(baseQueryReturnValue: unknown) {
You can set this globally in `createApi`, but you can also override the default value and have more granular control by passing `refetchOnMountOrArgChange` to each individual hook call or when dispatching the [`initiate`](#initiate) action.
You can set this globally in `createApi`, but you can also override the default value and have more granular control by passing `refetchOnFocus` to each individual hook call or when dispatching the [`initiate`](#initiate) action.
@@ -199,7 +251,7 @@ If you specify `track: false` when manually dispatching queries, RTK Query will
You can set this globally in `createApi`, but you can also override the default value and have more granular control by passing `refetchOnReconnect` to each individual hook call or when dispatching the [`initiate`](#initiate) action.
Copy file name to clipboardExpand all lines: docs/api/rtk-query/created-api/cache-management.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ hide_title: true
7
7
8
8
# API Slices: Cache Management Utilities
9
9
10
-
The API slice object includes cache management utilities that are used for implementing [optimistic updates](../../concepts/optimistic-updates.md). These are included in a `util` field inside the slice object.
10
+
The API slice object includes cache management utilities that are used for implementing [optimistic updates](../../../usage/rtk-query/optimistic-updates.md). These are included in a `util` field inside the slice object.
Copy file name to clipboardExpand all lines: docs/api/rtk-query/created-api/code-splitting.md
+10-8Lines changed: 10 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -7,9 +7,9 @@ hide_title: true
7
7
8
8
# API Slices: Code Splitting and Generation
9
9
10
-
Each API slice allows [additional endpoint definitions to be injected at runtime](../../concepts/code-splitting.md) after the initial API slice has been defined. This can be beneficial for apps that may have _many_ endpoints.
10
+
Each API slice allows [additional endpoint definitions to be injected at runtime](../../../usage/rtk-query/code-splitting.md) after the initial API slice has been defined. This can be beneficial for apps that may have _many_ endpoints.
11
11
12
-
The individual API slice endpoint definitions can also be split across multiple files. This is primarily useful for working with API slices that were [code-generated from an API schema file](../../concepts/code-generation.md), allowing you to add additional custom behavior and configuration to a set of automatically-generated endpoint definitions.
12
+
The individual API slice endpoint definitions can also be split across multiple files. This is primarily useful for working with API slices that were [code-generated from an API schema file](../../../usage/rtk-query/code-generation.md), allowing you to add additional custom behavior and configuration to a set of automatically-generated endpoint definitions.
13
13
14
14
Each API slice object has `injectEndpoints` and `enhanceEndpoints` functions to support these use cases.
15
15
@@ -18,11 +18,12 @@ Each API slice object has `injectEndpoints` and `enhanceEndpoints` functions to
0 commit comments