Kong / swrv

Stale-while-revalidate data fetching for Vue

Home Page:https://docs-swrv.netlify.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Middleware feature request

dmitriygoncharenko opened this issue · comments

Hi, I want to request a feature for this lib, kinda middleware to call js code before and after swr fetch. Or maybe it already implemented, please give an advice.

Your fetcher can be any asynchronous function, so you could call your custom code before fetch, make your actual fetch, then call additional code afterwards. Something like this:

const { data } =  composables.useSwrvRequest(
  'tasks',
  async () => {
    // Do something before the actual fetch
    await beforeFetchFunc()
    
    await axios.get('/testing')
    
    // Do something after fetch and return a promise
    return await afterFetchFunc()
  }
)

Additionally, you can gain insight into the current swrv state via useSwrvState