From 8e43f8e59db1b25d8c3b2c841267b5dd291997b4 Mon Sep 17 00:00:00 2001 From: Jackson Date: Mon, 29 Jan 2024 09:56:47 +1100 Subject: [PATCH 1/3] skipPollingIfUnfocused added to polling overview and query options in docs --- docs/rtk-query/api/created-api/hooks.mdx | 4 ++++ docs/rtk-query/usage/polling.mdx | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/docs/rtk-query/api/created-api/hooks.mdx b/docs/rtk-query/api/created-api/hooks.mdx index d6a9426466..6a44081832 100644 --- a/docs/rtk-query/api/created-api/hooks.mdx +++ b/docs/rtk-query/api/created-api/hooks.mdx @@ -251,6 +251,7 @@ type UseQuery = ( type UseQueryOptions = { pollingInterval?: number + skipPollingIfUnfocused?: boolean refetchOnReconnect?: boolean refetchOnFocus?: boolean skip?: boolean @@ -445,6 +446,7 @@ type UseQuerySubscriptionOptions = { skip?: boolean refetchOnMountOrArgChange?: boolean | number pollingInterval?: number + skipPollingIfUnfocused?: boolean refetchOnReconnect?: boolean refetchOnFocus?: boolean } @@ -485,6 +487,7 @@ type UseLazyQuery = ( type UseLazyQueryOptions = { pollingInterval?: number + skipPollingIfUnfocused?: boolean refetchOnReconnect?: boolean refetchOnFocus?: boolean selectFromResult?: (result: UseQueryStateDefaultResult) => any @@ -555,6 +558,7 @@ type UseLazyQuerySubscription = ( type UseLazyQuerySubscriptionOptions = { pollingInterval?: number + skipPollingIfUnfocused?: boolean refetchOnReconnect?: boolean refetchOnFocus?: boolean } diff --git a/docs/rtk-query/usage/polling.mdx b/docs/rtk-query/usage/polling.mdx index 2e85c1ed6d..63a1f38e2c 100644 --- a/docs/rtk-query/usage/polling.mdx +++ b/docs/rtk-query/usage/polling.mdx @@ -14,6 +14,10 @@ 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: +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_ + ```tsx no-transpile title="src/Pokemon.tsx" no-transpile import * as React from 'react' import { useGetPokemonByNameQuery } from './services/pokemon' From 6ec17457a0ac08d478513b8eb29549bd5f5273b2 Mon Sep 17 00:00:00 2001 From: Jackson Date: Mon, 29 Jan 2024 10:54:03 +1100 Subject: [PATCH 2/3] Wrapped option in tip admonition and added to example --- docs/rtk-query/usage/polling.mdx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/rtk-query/usage/polling.mdx b/docs/rtk-query/usage/polling.mdx index 63a1f38e2c..fd80e692a1 100644 --- a/docs/rtk-query/usage/polling.mdx +++ b/docs/rtk-query/usage/polling.mdx @@ -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
{data}
From 5e25dca82608923cf92d445b4ad17c856809b3e1 Mon Sep 17 00:00:00 2001 From: Jackson Date: Wed, 31 Jan 2024 14:16:38 +1100 Subject: [PATCH 3/3] Removed redundant default explanation --- docs/rtk-query/usage/polling.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/rtk-query/usage/polling.mdx b/docs/rtk-query/usage/polling.mdx index fd80e692a1..d7642e5dba 100644 --- a/docs/rtk-query/usage/polling.mdx +++ b/docs/rtk-query/usage/polling.mdx @@ -17,7 +17,7 @@ Polling gives you the ability to have a 'real-time' effect by causing a query to :::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 and is disabled by default_ +_Note: `skipPollingIfUnfocused` requires [`setupListeners`](../api/setupListeners.mdx) to have been called._ ::: ```tsx no-transpile title="src/Pokemon.tsx" no-transpile