diff --git a/src/hydration/hydration.ts b/src/core/hydration.ts similarity index 95% rename from src/hydration/hydration.ts rename to src/core/hydration.ts index b0aa9bc9d1..d10e1c83f0 100644 --- a/src/hydration/hydration.ts +++ b/src/core/hydration.ts @@ -1,12 +1,12 @@ -import type { QueryClient } from '../core/queryClient' -import type { Query, QueryState } from '../core/query' +import type { QueryClient } from './queryClient' +import type { Query, QueryState } from './query' import type { MutationKey, MutationOptions, QueryKey, QueryOptions, -} from '../core/types' -import type { Mutation, MutationState } from '../core/mutation' +} from './types' +import type { Mutation, MutationState } from './mutation' // TYPES diff --git a/src/core/index.ts b/src/core/index.ts index c3ecd06163..c09b2614de 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -12,8 +12,16 @@ export { focusManager } from './focusManager' export { onlineManager } from './onlineManager' export { hashQueryKey, isError } from './utils' export { isCancelledError } from './retryer' +export { dehydrate, hydrate } from './hydration' // Types export * from './types' export type { Query } from './query' export type { Logger } from './logger' +export type { + DehydrateOptions, + DehydratedState, + HydrateOptions, + ShouldDehydrateMutationFunction, + ShouldDehydrateQueryFunction, +} from './hydration' diff --git a/src/hydration/tests/hydration.test.tsx b/src/core/tests/hydration.test.tsx similarity index 99% rename from src/hydration/tests/hydration.test.tsx rename to src/core/tests/hydration.test.tsx index d8564dad6a..4bc3bc2087 100644 --- a/src/hydration/tests/hydration.test.tsx +++ b/src/core/tests/hydration.test.tsx @@ -1,5 +1,6 @@ import { mockNavigatorOnLine, sleep } from '../../react/tests/utils' -import { QueryCache, QueryClient } from '../..' +import { QueryCache } from '../queryCache' +import { QueryClient } from '../queryClient' import { dehydrate, hydrate } from '../hydration' async function fetchData(value: TData, ms?: number): Promise { diff --git a/src/hydration/index.ts b/src/hydration/index.ts index a52521402d..1c8a35e43a 100644 --- a/src/hydration/index.ts +++ b/src/hydration/index.ts @@ -1,11 +1,15 @@ -export { dehydrate, hydrate } from './hydration' -export { useHydrate, Hydrate } from './react' +// This package once contained these functions, but they have now been moved +// into the core and react packages. +// They are re-exported here to avoid a breaking change, but this package +// should be considered deprecated and removed in a future major version. +export { dehydrate, hydrate, useHydrate, Hydrate } from 'react-query' // Types export type { DehydrateOptions, DehydratedState, HydrateOptions, + ShouldDehydrateMutationFunction, ShouldDehydrateQueryFunction, -} from './hydration' -export type { HydrateProps } from './react' +} from '../core/hydration' +export type { HydrateProps } from '../react/Hydrate' diff --git a/src/hydration/react.tsx b/src/react/Hydrate.tsx similarity index 89% rename from src/hydration/react.tsx rename to src/react/Hydrate.tsx index 62fe2964f3..5221897403 100644 --- a/src/hydration/react.tsx +++ b/src/react/Hydrate.tsx @@ -1,7 +1,7 @@ import React from 'react' -import { useQueryClient } from 'react-query' -import { hydrate, HydrateOptions } from './hydration' +import { hydrate, HydrateOptions } from '../core' +import { useQueryClient } from './QueryClientProvider' export function useHydrate(state: unknown, options?: HydrateOptions) { const queryClient = useQueryClient() diff --git a/src/react/index.ts b/src/react/index.ts index 512d6d8e9f..e8bcdee432 100644 --- a/src/react/index.ts +++ b/src/react/index.ts @@ -13,8 +13,10 @@ export { useMutation } from './useMutation' export { useQuery } from './useQuery' export { useQueries } from './useQueries' export { useInfiniteQuery } from './useInfiniteQuery' +export { useHydrate, Hydrate } from './Hydrate' // Types export * from './types' export type { QueryClientProviderProps } from './QueryClientProvider' export type { QueryErrorResetBoundaryProps } from './QueryErrorResetBoundary' +export type { HydrateProps } from './Hydrate' diff --git a/src/hydration/tests/react.test.tsx b/src/react/tests/Hydrate.test.tsx similarity index 96% rename from src/hydration/tests/react.test.tsx rename to src/react/tests/Hydrate.test.tsx index 70a371fa3f..3a2b0b2f5c 100644 --- a/src/hydration/tests/react.test.tsx +++ b/src/react/tests/Hydrate.test.tsx @@ -1,9 +1,16 @@ import React from 'react' import { render } from '@testing-library/react' -import { QueryClient, QueryClientProvider, QueryCache, useQuery } from '../..' -import { dehydrate, useHydrate, Hydrate } from '../' -import { sleep } from '../../react/tests/utils' +import { + QueryClient, + QueryClientProvider, + QueryCache, + useQuery, + dehydrate, + useHydrate, + Hydrate, +} from '../..' +import { sleep } from './utils' describe('React hydration', () => { const fetchData: (value: string) => Promise = value => diff --git a/src/hydration/tests/ssr.test.tsx b/src/react/tests/ssr-hydration.test.tsx similarity index 97% rename from src/hydration/tests/ssr.test.tsx rename to src/react/tests/ssr-hydration.test.tsx index 4a764d59b8..f855b86352 100644 --- a/src/hydration/tests/ssr.test.tsx +++ b/src/react/tests/ssr-hydration.test.tsx @@ -2,10 +2,16 @@ import React from 'react' import ReactDOM from 'react-dom' import ReactDOMServer from 'react-dom/server' -import { useQuery, QueryClient, QueryClientProvider, QueryCache } from '../..' -import { dehydrate, hydrate } from '../' +import { + useQuery, + QueryClient, + QueryClientProvider, + QueryCache, + dehydrate, + hydrate, +} from '../..' import * as utils from '../../core/utils' -import { mockConsoleError, sleep } from '../../react/tests/utils' +import { mockConsoleError, sleep } from './utils' // This monkey-patches the isServer-value from utils, // so that we can pretend to be in a server environment