Skip to content

Commit

Permalink
feat(custom-data-provider): use query client defaults for custom data…
Browse files Browse the repository at this point in the history
… provider
  • Loading branch information
ismay committed Jul 12, 2021
1 parent e5e4f69 commit a566c4d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
15 changes: 2 additions & 13 deletions services/data/src/react/components/CustomDataProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { QueryClient, QueryClientProvider } from 'react-query'
import { DataEngine } from '../../engine'
import { CustomDataLink, CustomData, CustomLinkOptions } from '../../links'
import { DataContext } from '../context/DataContext'
import { queryClientOptions as queryClientDefaults } from './DataProvider'

interface CustomProviderInput {
children: React.ReactNode
Expand All @@ -11,23 +12,11 @@ interface CustomProviderInput {
queryClientOptions?: any
}

/**
* Disable automatic retries, which can cause tests to take unnecessarily long
* see: https://react-query.tanstack.com/reference/useQuery
*/
const defaultQueryClientOptions = {
defaultOptions: {
queries: {
retry: false,
},
},
}

export const CustomDataProvider = ({
children,
data,
options,
queryClientOptions = defaultQueryClientOptions,
queryClientOptions = queryClientDefaults,
}: CustomProviderInput) => {
const link = new CustomDataLink(data, options)
const engine = new DataEngine(link)
Expand Down
10 changes: 6 additions & 4 deletions services/data/src/react/components/DataProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ export interface ProviderInput {
children: React.ReactNode
}

const queryClient = new QueryClient({
export const queryClientOptions = {
defaultOptions: {
queries: {
// Disable automatic error retries
retry: false,
// Don't retry on mount if query has errored
retryOnMount: false,
// Retry on mount if query has errored
retryOnMount: true,
// Refetch on mount if data is stale
refetchOnMount: true,
// Don't refetch when the window regains focus
Expand All @@ -26,7 +26,9 @@ const queryClient = new QueryClient({
refetchOnReconnect: false,
},
},
})
}

const queryClient = new QueryClient(queryClientOptions)

export const DataProvider = (props: ProviderInput) => {
const config = {
Expand Down

0 comments on commit a566c4d

Please sign in to comment.