adapting and shit

This commit is contained in:
Elijah Lucian
2021-07-13 17:47:28 -06:00
parent 1af8209b99
commit 2b94223389
35 changed files with 163 additions and 160 deletions
+4 -4
View File
@@ -1,4 +1,4 @@
import Axios from 'axios'
import Axios, { AxiosResponse } from 'axios'
import React, { createContext, useContext } from 'react'
type Props = {
@@ -9,7 +9,7 @@ type Props = {
type Context = {
get: <T>(path: string) => Promise<T>
patch: <T>(path: string, body: Partial<T>) => Promise<T>
post: <T>(path: string, body: Partial<T>) => Promise<T>
post: <T, R = T>(path: string, body: Partial<T>) => Promise<R>
create: <T>(path: string, body: Partial<T>) => Promise<T>
destroy: (path: string) => Promise<string>
}
@@ -27,8 +27,8 @@ export const AppContextProvider = ({ children, baseURL }: Props) => {
const res = await axios.patch<T>(path, body)
return res.data
}
async function post<T>(path: string, body: Partial<T>) {
const res = await axios.post<T>(path, body)
async function post<T, R = T>(path: string, body: Partial<T>) {
const res = await axios.post<T, AxiosResponse<R>>(path, body)
return res.data
}
async function create<T>(path: string, body: Partial<T>) {