Skip to content

Commit 6ec1745

Browse files
committed
Wrapped option in tip admonition and added to example
1 parent 8e43f8e commit 6ec1745

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

docs/rtk-query/usage/polling.mdx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,21 @@ description: 'RTK Query > Usage > Polling: re-fetching data on a timer'
1414

1515
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:
1616

17+
:::tip
1718
Polling additionally has the ability to skip sending requests while the window is out of focus. To enable this behavior, pass `skipPollingIfUnfocused: true` to the `useQuery` hook or action creator.
1819

19-
_Note: `skipPollingIfUnfocused` requires [`setupListeners`](../api/setupListeners.mdx) to have been called_
20+
_Note: `skipPollingIfUnfocused` requires [`setupListeners`](../api/setupListeners.mdx) to have been called and is disabled by default_
21+
:::
2022

2123
```tsx no-transpile title="src/Pokemon.tsx" no-transpile
2224
import * as React from 'react'
2325
import { useGetPokemonByNameQuery } from './services/pokemon'
2426

2527
export const Pokemon = ({ name }: { name: string }) => {
26-
// Automatically refetch every 3s
28+
// Automatically refetch every 3s unless the window is out of focus
2729
const { data, status, error, refetch } = useGetPokemonByNameQuery(name, {
2830
pollingInterval: 3000,
31+
skipPollingIfUnfocused: true,
2932
})
3033

3134
return <div>{data}</div>

0 commit comments

Comments
 (0)