import { mergeConfigs } from './merge-config' ; import { normalize } from './normalize-args' ; import { useSWRConfig } from './use-swr-config' ; export const withArgs = < SWRType > ( hook ) => { return function useSWRArgs ( ... args ) { const fallbackConfig = useSWRConfig ( ) ; const [ key , fn , _config ] = normalize < any , any > ( args ) ; const config = mergeConfigs ( fallbackConfig , _config ) ; let next = hook ; const { use } = config ; if ( use ) { for ( let i = use . length ; i -- > 0 ; ) { next = use [ i ] ( next ) ; } } return next ( key , fn || config . fetcher , config ) ; } as unknown as SWRType ; } ;