import { normalize } from './normalize-args' ; import { Key , Fetcher , Middleware , SWRConfiguration , SWRHook } from '../types' ; export const withMiddleware = ( useSWR , middleware ) : SWRHook => { return < Data = any , Error = any > ( ... args ) => { const [ key , fn , config ] = normalize ( args ) ; const uses = ( config . use || [ ] ) . concat ( middleware ) ; return useSWR < Data , Error > ( key , fn , { ... config , use : uses } ) ; } ; } ;