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/rtk-query/api/created-api/hooks.mdx
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,15 +11,15 @@ hide_title: true
11
11
12
12
## Hooks Overview
13
13
14
-
The core RTK Query `createApi` method is UI-agnostic, in the same way that the Redux core library and Redux Toolkit are UI-agnostic. They are all plain JS logic that can be used anywhere.
14
+
The core RTK Query `createApi` method is UI-agnostic, in the same way that the Redux core library and Redux Toolkit are UI-agnostic. They are all plain JS logic that can be used anywhere. So, if you import `createApi` from `'@reduxjs/toolkit/query'`, it does not have any specific UI integrations included.
15
15
16
-
However, RTK Query also provides the ability to auto-generate React hooks for each of your endpoints. Since this specifically depends on React itself, RTK Query provides an alternate entry point that exposes a customized version of `createApi` that includes that functionality:
16
+
However, RTK Query also provides the ability to auto-generate React hooks for each of your endpoints. Since this specifically depends on React itself, RTK Query provides an additional entry point that exposes a customized version of `createApi` that includes that functionality:
If you have used the React-specific version of `createApi`, the generated `api` slice structure will also contain a set of React hooks. The primary endpoint hooks are available as `api.endpoints[endpointName].useQuery` or `api.endpoints[endpointName].useMutation`, matching how you defined that endpoint.
22
+
If you have used the React-specific version of `createApi`, the generated `api` slice structure will also contain a set of React hooks. The primary endpoint hooks are available as `api.endpoints[endpointName].useQuery`, `api.endpoints[endpointName].useMutation`, and `api.endpoints[endpointName].useInfiniteQuery`, matching how you defined that endpoint.
23
23
24
24
### Generated Hook Names
25
25
@@ -37,15 +37,15 @@ const { data } = api.useGetPostsQuery()
37
37
const [updatePost, { data }] =api.useUpdatePostMutation()
38
38
```
39
39
40
-
The general format is `use(Endpointname)(Query|Mutation)` - `use` is prefixed, the first letter of your endpoint name is capitalized, then `Query` or `Mutation` is appended depending on the type.
40
+
The general format is `use(Endpointname)(Query|Mutation|InfiniteQuery)` - `use` is prefixed, the first letter of your endpoint name is capitalized, then `Query` or `Mutation` or `InfiniteQuery` is appended depending on the type.
41
41
42
42
### Available Hooks
43
43
44
44
RTK Query provides additional hooks for more advanced use-cases, although not all are generated directly on the `api` object as well.
45
45
46
46
Most of the hooks are generated on a per-endpoint basis.
47
47
48
-
The full list of hooks generated in the React-specific version of `createApi` is as follows:
48
+
The full list of hooks generated in the React-specific version of `createApi` is:
49
49
50
50
- Endpoint-specific, generated the `api` object with a unique name and on the endpoint object with a generic name:
51
51
-[`useQuery`](#usequery) (all standard queries)
@@ -54,10 +54,10 @@ The full list of hooks generated in the React-specific version of `createApi` is
54
54
-[`useLazyQuery`](#uselazyquery) (all standard queries)
55
55
- Endpoint-specific, only generated on the endpoint object with a generic name:
0 commit comments