/** * @deprecated This method is deprecated. */ export const useFetch = () => { interface FetchConfig { baseUrl: string; headers: HeadersInit; } interface ApiResponse { data: T; status: number; } const DEFAULT_CONFIG: FetchConfig = { baseUrl: '/api/v1', headers: { 'Content-Type': 'application/json' } }; const buildQueryString = (params?: Record): string => { if (!params) return ''; return '?' + Object.entries(params) .map(([key, value]) => `${key}=${value}`) .join('&'); }; /** * @deprecated This function is deprecated. */ const createRequest = async ( endpoint: string, method: 'GET' | 'POST', options: RequestInit = {} ): Promise> => { const response = await fetch(`${DEFAULT_CONFIG.baseUrl}${endpoint}`, { method, mode: 'cors', headers: new Headers(DEFAULT_CONFIG.headers), ...options }); const data = await response.json(); return {data, status: response.status}; }; /** * @deprecated This function is deprecated. */ const get = async ( endpoint: string, queryParams?: Record ): Promise => { const query = buildQueryString(queryParams); const response = await createRequest(`${endpoint}${query}`, 'GET'); return response.data; }; /** * @deprecated This function is deprecated. */ const post = async (endpoint: string, payload: T): Promise => { const response = await createRequest(endpoint, 'POST', { body: JSON.stringify(payload) }); return response.data; }; return { get, post } }