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/usage-with-typescript.mdx
+8-9
Original file line number
Diff line number
Diff line change
@@ -467,7 +467,7 @@ export const api = createApi({
467
467
exportconst { useGetPostQuery } =api
468
468
```
469
469
470
-
```tsx title="Using skip in a component"
470
+
```tsx no-transpile title="Using skip in a component"
471
471
import { useGetPostQuery } from './api'
472
472
473
473
function MaybePost({ id }: { id?: number }) {
@@ -486,7 +486,7 @@ While you might be able to convince yourself that the query won't be called unle
486
486
487
487
RTK Query provides a `skipToken` export which can be used as an alternative to the `skip` option in order to skip queries, while remaining type-safe. When `skipToken` is passed as the query argument to `useQuery`, `useQueryState` or `useQuerySubscription`, it provides the same effect as setting `skip: true` in the query options, while also being a valid argument in scenarios where the `arg` might be undefined otherwise.
488
488
489
-
```tsx title="Using skipToken in a component"
489
+
```tsxno-transpile title="Using skipToken in a component"
Copy file name to clipboardexpand all lines: docs/rtk-query/usage/cache-behavior.mdx
+2-2
Original file line number
Diff line number
Diff line change
@@ -120,7 +120,7 @@ Calling the `refetch` function will force refetch the associated query.
120
120
121
121
Alternatively, you can dispatch the `initiate` thunk action for an endpoint, passing the option `forceRefetch: true` to the thunk action creator for the same effect.
122
122
123
-
```tsx title="Force refetch example"
123
+
```tsxno-transpile title="Force refetch example"
124
124
import { useDispatch } from'react-redux'
125
125
import { useGetPostsQuery } from'./api'
126
126
@@ -197,7 +197,7 @@ export const api = createApi({
197
197
})
198
198
```
199
199
200
-
```tsx title="Forcing refetch on component mount"
200
+
```tsxno-transpile title="Forcing refetch on component mount"
Copy file name to clipboardexpand all lines: docs/rtk-query/usage/migrating-to-rtk-query.mdx
+4-4
Original file line number
Diff line number
Diff line change
@@ -169,7 +169,7 @@ export type RootState = ReturnType<typeof store.getState>
169
169
170
170
In order to have the store accessible within our app, we will wrap our `App` component with a [`Provider`](https://react-redux.js.org/api/provider) component from `react-redux`.
@@ -276,7 +276,7 @@ Our implementation below provides the following behaviour in the component:
276
276
- When our component is mounted, if a request for the provided pokemon name has not already been sent for the session, send the request off
277
277
- The hook always provides the latest received `data` when available, as well as the request status booleans `isUninitialized`, `isPending`, `isFulfilled` & `isRejected` in order to determine the current UI at any given moment as a function of our state.
// onQueryStarted is useful for optimistic updates
58
62
// The 2nd parameter is the destructured `MutationLifecycleApi`
@@ -177,7 +181,7 @@ When using `fixedCacheKey`, the `originalArgs` property is not able to be shared
177
181
178
182
This is a modified version of the complete example you can see at the bottom of the page to highlight the `updatePost` mutation. In this scenario, a post is fetched with `useQuery`, and then an `EditablePostName` component is rendered that allows us to edit the name of the post.
In the following example, you'll see `Loading` on the initial query, but then as you move forward we'll use the next/previous buttons as a _fetching_ indicator while any non-cached query is performed. When you go back, the cached data will be served instantaneously.
Copy file name to clipboardexpand all lines: docs/rtk-query/usage/polling.mdx
+1-1
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@ description: 'RTK Query > Usage > Polling: re-fetching data on a timer'
14
14
15
15
Polling gives you the ability to have a 'real-time' effect by causing a query to run at a specified interval. To enable polling for a query, pass a `pollingInterval` to the `useQuery` hook or action creator with an interval in milliseconds:
@@ -199,7 +203,7 @@ For query endpoints, RTK Query maintains a semantic distinction between `isLoadi
199
203
200
204
This distinction allows for greater control when handling UI behavior. For example, `isLoading` can be used to display a skeleton while loading for the first time, while `isFetching` can be used to grey out old data when changing from page 1 to page 2 or when data is invalidated and re-fetched.
201
205
202
-
```tsx title="Managing UI behavior with Query Loading States"
206
+
```tsxno-transpile title="Managing UI behavior with Query Loading States"
203
207
import { Skeleton } from'./Skeleton'
204
208
import { useGetPostsQuery } from'./api'
205
209
@@ -236,7 +240,7 @@ shown. If posts for the current user have previously been fetched, and are re-fe
236
240
result of a mutation), the UI will show the previous data, but will grey out the data. If the user
237
241
changes, it will instead show the skeleton again as opposed to greying out data for the previous user.
238
242
239
-
```tsx title="Managing UI behavior with currentData"
243
+
```tsxno-transpile title="Managing UI behavior with currentData"
240
244
import { Skeleton } from'./Skeleton'
241
245
import { useGetPostsByUserQuery } from'./api'
242
246
@@ -274,7 +278,7 @@ Sometimes you may have a parent component that is subscribed to a query, and the
274
278
275
279
`selectFromResult` allows you to get a specific segment from a query result in a performant manner. When using this feature, the component will not rerender unless the underlying data of the selected item has changed. If the selected item is one element in a larger collection, it will disregard changes to elements in the same collection.
276
280
277
-
```tsx title="Using selectFromResult to extract a single result"
281
+
```tsxno-transpile title="Using selectFromResult to extract a single result"
278
282
function PostsList() {
279
283
const { data: posts } =api.useGetPostsQuery()
280
284
@@ -301,7 +305,7 @@ function PostById({ id }: { id: number }) {
301
305
302
306
Note that a shallow equality check is performed on the overall return value of `selectFromResult` to determine whether to force a rerender. i.e. it will trigger a rerender if any of the returned object values change reference. If a new array/object is created and used as a return value within the callback, it will hinder the performance benefits due to being identified as a new item each time the callback is run. When intentionally providing an empty array/object, in order to avoid re-creating it each time the callback runs, you can declare an empty array/object outside of the component in order to maintain a stable reference.
303
307
304
-
```tsx title="Using selectFromResult with a stable empty array"
308
+
```tsxno-transpile title="Using selectFromResult with a stable empty array"
305
309
// An array declared here will maintain a stable reference rather than be re-created again
0 commit comments