HEX
Server: LiteSpeed
System: Linux standart113.isimtescil.net 4.18.0-553.132.1.lve.el8.x86_64 #1 SMP Wed Jun 17 12:00:40 UTC 2026 x86_64
User: guvercin.org.tr_ (1560)
PHP: 8.1.34
Disabled: dl,exec,shell_exec,system,passthru,popen,pclose,proc_open,mail,proc_nice,proc_terminate,proc_get_status,proc_close,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setpgid,posix_setsid,posix_setuid,escapeshellcmd,escapeshellarg,shell-exec,crack_check,crack_closedict,crack_getlastmessage,crack_opendict,symlink,ini_restore,posix_getpwuid,ini_sefind,grep,sh2_exec,diskfreespace,disk_free_space,disk_total_space,highlight_file,link,lchgrp,lchown,show_source,sendmail
Upload Files
File: /home/guvercin.org.tr_/public_html/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])
}