Middleware feature request
dmitriygoncharenko opened this issue · comments
Dmitriy Goncharenko commented
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.
Adam DeHaven commented
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