diff --git a/docs/src/pages/docs/api.md b/docs/src/pages/docs/api.md index 072d4c8d77..b2c5332f00 100644 --- a/docs/src/pages/docs/api.md +++ b/docs/src/pages/docs/api.md @@ -31,7 +31,6 @@ const { refetchInterval, refetchIntervalInBackground, queryFnParamsFilter, - refetchOnMount, isDataEqual, onError, onSuccess, @@ -112,10 +111,6 @@ const queryInfo = useQuery({ - Optional - If set, this will mark any `initialData` provided as stale and will likely cause it to be refetched on mount - If a function is passed, it will be called only when appropriate to resolve the `initialStale` value. This can be useful if your `initialStale` value is costly to calculate. -- `refetchOnMount: Boolean` - - Optional - - Defaults to `true` - - If set to `false`, will disable additional instances of a query to trigger background refetches - `queryFnParamsFilter: Function(args) => filteredArgs` - Optional - This function will filter the params that get passed to `queryFn`. @@ -664,7 +659,6 @@ const queryConfig = { refetchOnWindowFocus: true, refetchInterval: false, queryFnParamsFilter: identity, - refetchOnMount: true, isDataEqual: deepEqual, onError: noop, onSuccess: noop, diff --git a/src/core/config.js b/src/core/config.js index 9222c5c808..6071e5386e 100644 --- a/src/core/config.js +++ b/src/core/config.js @@ -16,7 +16,6 @@ export const DEFAULT_CONFIG = { refetchOnWindowFocus: true, refetchInterval: false, queryFnParamsFilter: identity, - refetchOnMount: true, isDataEqual: deepEqual, onError: noop, onSuccess: noop, diff --git a/src/core/queryInstance.js b/src/core/queryInstance.js index 6e3d925295..6c8602534d 100644 --- a/src/core/queryInstance.js +++ b/src/core/queryInstance.js @@ -50,14 +50,12 @@ export function makeQueryInstance(query, onStateUpdate) { instance.run = async () => { try { - // Perform the refetch for this query if necessary - if ( + if( query.config.enabled && // Don't auto refetch if disabled !query.wasSuspended && // Don't double refetch for suspense - query.state.isStale && // Only refetch if stale - (query.config.refetchOnMount || query.instances.length === 1) + query.state.isStale // Only refetch if stale ) { - await query.fetch() + await query.fetch(); } query.wasSuspended = false diff --git a/src/react/tests/ReactQueryConfigProvider.test.js b/src/react/tests/ReactQueryConfigProvider.test.js index 9148822a69..ef489429c3 100644 --- a/src/react/tests/ReactQueryConfigProvider.test.js +++ b/src/react/tests/ReactQueryConfigProvider.test.js @@ -97,7 +97,6 @@ describe('ReactQueryConfigProvider', () => { const config = { queries: { refetchOnWindowFocus: false, - refetchOnMount: false, retry: false, }, } @@ -143,7 +142,7 @@ describe('ReactQueryConfigProvider', () => { await waitFor(() => rendered.findByText('Data: data')) // tear down and unmount - // so we are NOT passing the config above (refetchOnMount should be `true` by default) + // so we are NOT passing the config above fireEvent.click(rendered.getByText('unmount')) act(() => { @@ -161,15 +160,12 @@ describe('ReactQueryConfigProvider', () => { const parentConfig = { queries: { - refetchOnMount: false, onSuccess: parentOnSuccess, }, } const childConfig = { queries: { - refetchOnMount: true, - // Override onSuccess of parent, making it a no-op onSuccess: undefined, }, diff --git a/types/index.d.ts b/types/index.d.ts index dc6e925ccd..6d2cd9453a 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -236,7 +236,6 @@ export interface BaseQueryOptions { refetchInterval?: false | number refetchIntervalInBackground?: boolean refetchOnWindowFocus?: boolean - refetchOnMount?: boolean onSuccess?: (data: TResult) => void onError?: (err: TError) => void onSettled?: (data: TResult | undefined, error: TError | null) => void