Skip to main content

Parameters

ParameterTypeDefaultHooksDescription
baseURLstringRequiredAllThe base URL for your API, e.g., http://localhost:3000/.
routestringRequiredAllThe API endpoint for the request, e.g., user/update.
idstringundefinedphantomPatch, phantomPut, phantomDeleteID of the resource to be appended to the route, e.g., user/update/:id.
tokenstringundefinedAllAuthorization token sent in the Authorization header as Bearer <token>.
onUnauthorized() => void() => {}AllCallback for handling 401 Unauthorized responses, such as redirecting to a login page.
initialState`Tnull`nullAll
paramsRecord<string, any>undefinedphantomGetQuery parameters for GET requests.
headersRecord<string, string>{}phantomPost, phantomPatch, phantomDeleteCustom headers to include in the request.
restHeaderRecord<string, string>undefinedphantomGetCustom headers for GET requests.
contentType"application/json" | "multipart/form-data" | "application/x-www-form-urlencoded""application/json"phantomPost, phantomPatchContent-Type of the request body.
fetchOnMountbooleantruephantomGetWhether to fetch data immediately upon component mount.
asyncAwaitbooleantruephantomGetIf true, uses async/await for requests. If false, uses Promises.
axiosOptionsAxiosRequestConfig{}AllAdditional Axios options like timeout, base headers, etc.
cloudinaryUploadCloudinaryUploadOptionsundefinedphantomPost, phantomPatchConfiguration for uploading files to Cloudinary.
getLatestDatastringundefinedphantomPost, phantomPatch, phantomDelete, phantomPutEndpoint to refetch updated data after a successful mutation.

Notes:

  1. Shared Parameters: baseURL, route, token, onUnauthorized, initialState, and axiosOptions are used across all hooks (phantomGet, phantomPost, phantomPatch, phantomDelete, phantomPut).
  2. Unique Parameters:
    • params, restHeader, fetchOnMount, and asyncAwait are specific to phantomGet.
    • contentType and cloudinaryUpload are specific to mutation hooks (phantomPost, phantomPatch).
    • id is required for resource-specific requests (phantomPatch, phantomDelete, phantomPut).
  3. Custom Features: getLatestData allows fetching updated data after a mutation, enhancing reactivity and data consistency.