Skip to content

Commit

Permalink
Wrapped option in tip admonition and added to example
Browse files Browse the repository at this point in the history
  • Loading branch information
riqts committed Jan 28, 2024
1 parent 8e43f8e commit 6ec1745
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions docs/rtk-query/usage/polling.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,21 @@ description: 'RTK Query > Usage > Polling: re-fetching data on a timer'

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:

:::tip
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.

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

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

export const Pokemon = ({ name }: { name: string }) => {
// Automatically refetch every 3s
// Automatically refetch every 3s unless the window is out of focus
const { data, status, error, refetch } = useGetPokemonByNameQuery(name, {
pollingInterval: 3000,
skipPollingIfUnfocused: true,
})

return <div>{data}</div>
Expand Down

0 comments on commit 6ec1745

Please sign in to comment.