SILENT KILLERPanel

Current Path: > home > codekrsu > > shopceylon.store > wp-content > plugins > code-snippets > > js > hooks >


Operation   : Linux premium131.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
Software     : Apache
Server IP    : 162.0.232.56 | Your IP: 216.73.216.111
Domains      : 1034 Domain(s)
Permission   : [ 0755 ]

Files and Folders in: /home/codekrsu//shopceylon.store/wp-content/plugins/code-snippets//js/hooks/

NameTypeSizeLast ModifiedActions
useAxios.ts File 1368 bytes November 27 2024 21:52:46.
useSnippetForm.tsx File 3408 bytes November 27 2024 21:52:46.
useSnippetSubmit.ts File 2696 bytes February 14 2025 13:16:14.
useSnippets.ts File 2640 bytes November 27 2024 21:52:46.

Reading File: /home/codekrsu//shopceylon.store/wp-content/plugins/code-snippets//js/hooks//useAxios.ts

import { useMemo } from 'react'
import axios from 'axios'
import type { AxiosInstance, AxiosResponse, CreateAxiosDefaults } from 'axios'

export interface AxiosAPI {
	get: <T>(url: string) => Promise<AxiosResponse<T, never>>
	post: <T, D>(url: string, data?: D) => Promise<AxiosResponse<T, D>>
	del: <T>(url: string) => Promise<AxiosResponse<T, never>>
	axiosInstance: AxiosInstance
}

const debugRequest = async <T, D = never>(
	method: 'GET' | 'POST' | 'PUT' | 'DELETE',
	url: string,
	doRequest: Promise<AxiosResponse<T, D>>,
	data?: D
): Promise<AxiosResponse<T, D>> => {
	console.debug(`${method} ${url}`, ...data ? [data] : [])
	const response = await doRequest
	console.debug('Response', response)
	return response
}

export const useAxios = (defaultConfig: CreateAxiosDefaults): AxiosAPI => {
	const axiosInstance = useMemo(() => axios.create(defaultConfig), [defaultConfig])

	return useMemo((): AxiosAPI => ({
		get: <T>(url: string): Promise<AxiosResponse<T, never>> =>
			debugRequest('GET', url, axiosInstance.get<T, AxiosResponse<T, never>, never>(url)),

		post: <T, D>(url: string, data?: D) =>
			debugRequest('POST', url, axiosInstance.post<T, AxiosResponse<T, D>, D>(url, data), data),

		del: <T>(url: string) =>
			debugRequest('DELETE', url, axiosInstance.delete<T, AxiosResponse<T, never>, never>(url)),

		axiosInstance
	}), [axiosInstance])
}

SILENT KILLER Tool