Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

ReactQueryConfigProvider.tsx

35 lines808 Bytes

1import React from 'react'
2​
3import { mergeReactQueryConfigs } from '../core/config'
4import { ReactQueryConfig } from '../core/types'
5​
6const configContext = React.createContext<ReactQueryConfig | undefined>(
7 undefined
8)
9​
10export function useContextConfig() {
11 return React.useContext(configContext)
13​
14export interface ReactQueryConfigProviderProps {
15 config: ReactQueryConfig
17​
18export const ReactQueryConfigProvider: React.FC<ReactQueryConfigProviderProps> = ({
19 config,
20 children,
21}) => {
22 const parentConfig = useContextConfig()
23​
24 const mergedConfig = React.useMemo(
25 () =>
26 parentConfig ? mergeReactQueryConfigs(parentConfig, config) : config,
27 [config, parentConfig]
28 )
29​
30 return (
31 <configContext.Provider value={mergedConfig}>
32 {children}
33 </configContext.Provider>
34 )