Better Fetch

Hooks

Hooks are functions that are called at different stages of the request lifecycle.

fetch.ts
import {  } from "@better-fetch/fetch";
 
const  = ({
    : "http://localhost:3000",
    () {
        return ;
    },
    () {
        return .
    },
    () {
    },
    () {
    },
})
 

On Request

a callback function that will be called when a request is about to be made. The function will be called with the request context as an argument and it's expected to return the modified request context.

fetch.ts
import {  } from "@better-fetch/fetch";
 
const  = ({
    : "http://localhost:3000",
    () {
        // do something with the context
        return ;
    },
})

On Response

a callback function that will be called when a response is received. The function will be called with the response context which includes the response and the requestContext as an argument and it's expected to return response.

fetch.ts
import {  } from "@better-fetch/fetch";
 
const  = ({
    : "http://localhost:3000",
    () {        
        // do something with the context
        return . // return the response
    },
})

On Success and On Error

on success and on error are callbacks that will be called when a request is successful or when an error occurs. The function will be called with the response context as an argument and it's not expeceted to return anything.

fetch.ts
import {  } from "@better-fetch/fetch";
 
const  = ({
    : "http://localhost:3000",
    () {
        // do something with the context
    },
    () {
        // do something with the context
    },
})

On this page