mergeFetchHooks

Gitlab
A utility function for merging fetch hooks.
Added since: v0.2.0
Last changed:

Usage

The mergeFetchHooks function is a utility function that merges multiple fetch hooks into a single fetch hook.

This utility is useful when you need to combine fetch hooks from different sources, such as global hooks, module-specific hooks, and user-defined hooks.

Basic example

app/utils/customHooks.ts
const 
hooks1
= {
onRequest
: (
ctx
) =>
console
.
log
('Global request hook'),
onResponse
: (
ctx
) =>
console
.
log
('Global response hook')
}; const
hooks2
= {
onRequest
: (
ctx
) =>
console
.
log
('Module request hook'),
onResponseError
: (
ctx
) =>
console
.
error
('Module error hook')
}; const
merged
= mergeFetchHooks(
hooks1
,
hooks2
);
// Result will have both onRequest hooks and both error handling hooks

Type Definition

function 
mergeFetchHooks
(...
hooks
:
FetchHooks
[]): FetchHooks

API Reference

Params

...hooks
FetchHooks[] required
A spread of FetchHooks objects to merge.

Return Value

FetchHooks
The merged fetch hook.

Changelog

v0.2.0

on

#a6f8148c

-

feat: added the mergeFetchHooks utility