export const useFetch = () => { const ver = 'v1'; const get = async (endpoint: string) => { const data = await fetch(`/api/${ ver }/${ endpoint }`, { method: 'GET', mode: 'cors', headers: new Headers({ 'Content-Type': 'application/json' }) }); return await data.json() as T; }; const post = async (endpoint: string, payload: T) => { const data = await fetch(`/api/${ ver }/${ endpoint }`, { method: 'POST', mode: 'cors', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload) }); return await data.json() as U; }; return { get, post } }